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

提取不重复的整数

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

#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
    int a;
    while (cin >> a) {  // 注意 while 处理多个 case
        set<int> s;
        vector<int> v;
        string str = to_string(a);
        string str1;
        for (int i = str.size() - 1; i >= 0; i--) {
            // 强制转换的时候还要注意ascii码的问题
            // '7'-'0' = 7,背后是55-48
            int b = str[i] - '0';
            if (s.find(b) == s.end()) {
                v.push_back(b);
            }
            s.insert(b);
        }

        for (int i = 0; i < v.size(); i++) {
            str1 += to_string(v[i]);
        }
        int res = stoi(str1);
        cout << res;
    }
    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
09-08 17:17
同济大学 Java
狗不理fe:里面的人劝一句,别来虾,我们部门24校招生淘汰率30%,还有一些人说有一年保护期,不可能!!!
我的秋招日记
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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