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

提取不重复的整数

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

#include <bits/stdc++.h>
#include <string>
using namespace std;

int main() {
   int nums; cin>> nums;
   string str = to_string(nums);
   unordered_set<char> set;
   reverse(str.begin(), str.end());
   string res;
   for(char c:str)
        if(set.count(c) != 1){
            res += c;
            set.insert(c);
        }
    cout << stoi(res) << endl;
}
// 64 位输出请用 printf("%lld")
const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let str = ''
rl.on('line', function (line) {
    str = JSON.stringify(parseInt(line))
});
rl.on('close', ()=>{
    let set = new Set<string>(), res:string = ''
    str.split("")
       .reverse()
       .forEach(
        (item:string)=>{
            if(!set.has(item))
            {
                set.add(item)
                res += item
            }
        }
    )
    return console.log(res)
})

全部评论

相关推荐

09-01 21:40
已编辑
同济大学 Java
点赞 评论 收藏
分享
阿武同学:基本信息保留前面三行,其他的可以全部删掉,邮箱最重要的你没写,主修课程精简到8个以内,实习里面2/3/4都是水内容的,非要写的话建议两到三句话,项目经历排版优化下,自我评价缩到三行
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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