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

提取不重复的整数

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

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

int main(){
    int a;
    int n=1;
    cin >> a;
    map<int,int> s;
    while (a/10 != 0){
        if (s[a%10]==0) s[a%10]=n++;
        a = a/10;
    }
    if (s[a%10]==0) s[a%10]=n;

    for(int i=1;i<=9;i++){
        for (auto x : s){
            if (x.second == i) cout<< x.first;
        }
    }

}

本来很简单的用数组就可以解决的题目,看见tag有个哈希就用map绕了一下,害。顺便学习了一下set和unordered_set

全部评论

相关推荐

04-16 12:49
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
04-06 11:24
已编辑
太原学院 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务