Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14584 Accepted Submission(s): 6313
1 #include <iostream>
2 using namespace std; 3 int a[6000]; 4 int Min(int a,int b,int c,int d) 5 { 6 int t; 7 t = a<b?a:b; 8 t = t<c?t:c; 9 t = t<d?t:d; 10 return t; 11 } 12 int main() 13 { 14 int n; 15 a[1] = 1; 16 int a1=1,a2=1,a3=1,a4=1; 17 int e1,e2,e3,e4; 18 for(int i=2;i<6000;i++){ 19 e1 = a[a1]*2; 20 e2 = a[a2]*3; 21 e3 = a[a3]*5; 22 e4 = a[a4]*7; 23 a[i] = Min(e1,e2,e3,e4); 24 if(a[i]==e1) 25 a1++; 26 if(a[i]==e2) 27 a2++; 28 if(a[i]==e3) 29 a3++; 30 if(a[i]==e4) 31 a4++; 32 } 33 while(cin>>n){ 34 if(n==0) 35 break; 36 if(n%100==11 || n%100==12 || n%100==13) 37 cout<<"The "<<n<<"th humble number is "<<a[n]<<'.'<<endl; 38 else { 39 int t = n%10; 40 switch(t){ 41 case 0:cout<<"The "<<n<<"th humble number is "<<a[n]<<'.'<<endl;break; 42 case 1:cout<<"The "<<n<<"st humble number is "<<a[n]<<'.'<<endl;break; 43 case 2:cout<<"The "<<n<<"nd humble number is "<<a[n]<<'.'<<endl;break; 44 case 3:cout<<"The "<<n<<"rd humble number is "<<a[n]<<'.'<<endl;break; 45 default:cout<<"The "<<n<<"th humble number is "<<a[n]<<'.'<<endl;break; 46 } 47 } 48 } 49 return 0; 50 }
Freecode : www.cnblogs.com/yym2013