标签:
1 #include <iostream> 2 using namespace std; 3 4 int sum_10; 5 int sum_12; 6 int sum_16; 7 int fun_10(int num); 8 int fun_12(int num); 9 int fun_16(int num); 10 int main() 11 { 12 // freopen("acm.acm","r",stdin); 13 sum_10 = 0; 14 sum_12 = 0; 15 sum_16 = 0; 16 int i; 17 for(i = 1000; i <= 9999; ++ i) 18 { 19 sum_10 = fun_10(i); 20 sum_12 = fun_12(i); 21 if(sum_10 != sum_12) 22 { 23 continue; 24 } 25 sum_16 = fun_16(i); 26 if(sum_10 == sum_16 && sum_12 == sum_10) 27 { 28 cout<<i<<endl; 29 } 30 } 31 } 32 33 int fun_10(int num) 34 { 35 int sum = 0; 36 while(num) 37 { 38 sum += num%10; 39 num /= 10; 40 } 41 return sum; 42 } 43 44 int fun_12(int num) 45 { 46 int sum = 0; 47 while(num) 48 { 49 sum += num%12; 50 num /= 12; 51 } 52 return sum; 53 } 54 55 int fun_16(int num) 56 { 57 int sum = 0; 58 while(num) 59 { 60 sum += num%16; 61 num /= 16; 62 } 63 return sum; 64 }
标签:
原文地址:http://www.cnblogs.com/gavinsp/p/4566715.html