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

提取不重复的整数

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

#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

int main() {
    long a;
    cin >> a;
    string str = to_string(a);
    reverse(str.begin(),str.end());
    unordered_map<char,int>map;
    vector<int> array;
    for(char &c : str){
        if(map.count(c) == 0){
            map[c]++;
            array.push_back(c-'0');
        }
    }
    //reverse(array.begin(),array.end());
    for(int num : array){
        cout << num ;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

根据前面出现过的题目,模仿出来的

全部评论

相关推荐

05-09 13:22
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务