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

提取不重复的整数

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

  1. int 转换成string std::to_string 2.string排序 reverse 3.判断是否重复重要结构 unordered_set速度比set快 (注意里面不是按照插入的先后排序的)
#include <unordered_set>
#include <set>
#include <vector>
using namespace std;
#include <algorithm>
int main()
{
    int in_data = 0;
    while(cin>>in_data)
    {
        unordered_set<char> un_set;
        vector<char> v;
        string str_in_data = std::to_string(in_data);
        string::iterator it = str_in_data.begin();
        reverse(str_in_data.begin(),str_in_data.end());
        string res;
        for (auto &&i : str_in_data)
        {
            if(un_set.count(i)!=1)
            {
                res+=i;
                un_set.insert(i);
            }

        }
        cout << res;       
    }
    return 0;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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