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

提取不重复的整数

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

使用unordered_set来去除重复的整数

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

int main() {
    int input = 0;
    cin >> input;
    unordered_set<int> hash;
    int res = 0;
    while(input){
        int backend = input % 10;
        if(hash.find(backend) == hash.end()){
            res *= 10;
            res += backend;
            hash.insert(backend);       
        }
        input /= 10;
    }
    cout << res << endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

我看看你怎么个事来
牛牛爱吃草草:我看看你怎么个事来
点赞 评论 收藏
分享
难怪不开摄像头,全是简单的性格题,比大疆友善多了
NULL10086:今早上发的测评,我这还没做呢,官网上已经显示挂了
投递大疆等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务