http://acm.hdu.edu.cn/showproblem.php?pid=1197
进制转换问题,题意为给定一个4位的十进制数,求它各个数位的和,然后问是否它的12进制和16进制的和都相等,输出2992~10000之间所有满足条件的数;第二种解法有点二。但是,偷懒时,总是pe
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int jz( int num , int j ) { int sum = 0 ; while( num ) { sum += num % j ; num /= j ; } return sum ; } int main() { for( int i = 2992 ; i <= 9999 ; ++i ) { int a = jz( i , 10 ) ; int b = jz( i , 12 ) ; int c = jz( i , 16 ) ; if( a == b && a == c ) cout << i << endl ; } return 0 ; }
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int main() { cout << "2992" <<endl ; cout <<"2993"<< endl ; cout <<"2994"<< endl ; cout <<"2995"<< endl ; cout <<"2996"<< endl; cout <<"2997"<< endl; cout<<"2998"<<endl; cout<<"2999"<<endl; cout<<"4470"<<endl; cout<<"4471"<<endl; cout<<"4472"<<endl; cout<<"4473"<<endl; cout<<"4474"<<endl; cout<<"4475"<<endl; cout<<"4970"<<endl; cout<<"4971"<<endl; cout<<"4972"<<endl; cout<<"4973"<<endl; cout<<"4974"<<endl; cout<<"4975"<<endl; cout<<"5460"<<endl; cout<<"5461"<<endl; cout<<"5462"<<endl; cout<<"5463"<<endl; cout<<"5464"<<endl; cout<<"5465"<<endl; cout<<"5466"<<endl; cout<<"5467"<<endl; cout<<"5468"<<endl; cout<<"5469"<<endl; cout<<"5960"<<endl; cout<<"5961"<<endl; cout<<"5962"<<endl; cout<<"5963"<<endl; cout<<"6456"<<endl; cout<<"6457"<<endl; cout<<"6458"<<endl; cout<<"6459"<<endl; cout<<"7440"<<endl; cout<<"7441"<<endl; cout<<"7442"<<endl; cout<<"7443"<<endl; cout<<"7444"<<endl; cout<<"7445"<<endl; cout<<"7446"<<endl; cout<<"7447"<<endl; cout<<"7448"<<endl; cout<<"7449"<<endl; cout<<"7940"<<endl; cout<<"7941"<<endl; cout<<"7942"<<endl; cout<<"7943"<<endl; cout<<"8436"<<endl; cout<<"8437"<<endl; cout<<"8438"<<endl; cout<<"8439"<<endl; cout<<"9424"<<endl; cout<<"9425"<<endl; cout<<"9426"<<endl; cout<<"9427"<<endl; cout<<"9428"<<endl; cout<<"9429"<<endl; cout<<"9924"<<endl; cout<<"9925"<<endl; cout<<"9926"<<endl; cout<<"9927"<<endl; cout<<"9928"<<endl; cout<<"9929"<<endl; return 0 ; }