题解 | #提取不重复的整数#

提取不重复的整数

https://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1

#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;

int main() 
{
    int n=0;
    vector<int> arr;
    unordered_set<int> mytab;
    int tmp=0;

    cin>>n;
    tmp=n;

    while(tmp!=0)
    {
        int b=tmp%10;
        if(mytab.count(b)==0)
        {
            mytab.insert(b);
            arr.push_back(b);
        }
        tmp=(tmp-b)/10;
    }
    
    int res=0;
    for(int i=0;i<arr.size();i++)
    {
        res=res*10+arr[i];
    }
    cout<<res<<endl;
    
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

大摆哥:刚好要做个聊天软件,直接让你帮他干活了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务