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

提取不重复的整数

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;
}

全部评论

相关推荐

06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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