题解 | #明明的随机数#
提取不重复的整数
http://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
首先通过取余数分别获取个位数,十位数,百位数....然后在用一个表来记录所获取的数,如果表中没有这个数,则将该数添加到表中,并将该数添加到队列中,如果这个数表中已经出现,则直接跳过获取下一位的数,直到余数为0。
然后就可以通过队列的特性,先入先出,将每位数输出打印。
#include <iostream>
#include <map>
#include <queue>
using namespace std;
int main()
{
long int n;
cin >> n;
map <int, int> num;
queue<int> q;
while(n)
{
if(num.find(n%10) == num.end())
{
num.insert(pair<int, int>(n%10, 1));
q.push(n%10);
n = n/10;
}
else
{
n = n/10;
}
}
while(!q.empty())
{
int a = q.front();
q.pop();
cout << a ;
}
return 0;
}

