Project Euler Homework

052.cpp

00001 #include <iostream>
00002 #include <set>
00003 using namespace std;
00004 unsigned sort_digits(unsigned x)
00005 {
00006         multiset<int> nos;
00007         for (unsigned k=x;k>0;k/=10)
00008                 nos.insert(k%10);
00009 
00010         unsigned sorted_num = 0;
00011         for (multiset<int>::iterator p=nos.begin();p!=nos.end();p++)
00012                 sorted_num= sorted_num*10+*p;
00013         return sorted_num;
00014 }
00015 
00016 int main()
00017 {
00018         unsigned x;
00019         for (x=1;x!=0;x++) {
00020                 unsigned ref = sort_digits(x);
00021                 if (ref == sort_digits(2*x) &&
00022                         ref == sort_digits(3*x) &&
00023                         ref == sort_digits(4*x) &&
00024                         ref == sort_digits(5*x) &&
00025                         ref == sort_digits(6*x) )
00026                         break;
00027         }
00028         cout << x << endl;
00029         return 0;
00030 }
 All Classes Files Functions Variables