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

提取不重复的整数

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

#include <string>
#include <iostream>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int arr[10] = {0};
    int num;
    string str;
    cin >> num;
    str = to_string(num);//int型转string型
    int size = str.size();
    
    vector<int> vec;
    for(int i = size - 1; i >= 0; i--)
    {
        int b = str[i] - '0';
        if(arr[b] == 0)
        {
            arr[b]++;
            vec.push_back((str[i]-'0'));
        }
    }
    
    for(int i = 0; i < vec.size(); i++){
        cout << vec[i];
    }
    return 0;
}

全部评论

相关推荐

写不来代码的小黑:这么小的城市能有做it的公司也不容易
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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