Description
Input
Output
Sample Input
Sample Output
1 #include<cstdio> 2 #include<string.h> 3 using namespace std; 4 const int MAXN=5843; 5 int num2=0,num3=0,num5=0,num7=0; 6 long long s[MAXN]; 7 void Sort()//sort函数是用来求humble number数组的 8 { 9 s[0]=1; 10 s[num2]=1,s[num3]=1,s[num5]=1; 11 long long min=s[num2]*2; 12 int num2=0,num3=0,num5=0,num7=0; 13 for(int i=1;i<5843;i++) 14 { 15 16 min=s[num2]*2; 17 if(min>s[num3]*3) 18 min=s[num3]*3; 19 if(min>s[num5]*5) 20 min=s[num5]*5; 21 if(min>s[num7]*7) 22 min=s[num7]*7; 23 s[i]=min; 24 // printf("%d ",s[i]); 25 //printf("%d ",min); 26 if(min==s[num2]*2) 27 num2++; 28 if(min==s[num3]*3) 29 num3++; 30 if(min==s[num5]*5) 31 num5++; 32 if(min==s[num7]*7) 33 num7++; 34 } 35 } 36 int main() 37 { 38 int n; 39 Sort(); 40 while(scanf("%d",&n)!=EOF&&n) 41 { 42 if(n%10==1&&n%100!=11&&n!=11)//当时卡在n%100!=11和12,13这里了,wa了几次! 43 printf("The %dst humble number is ",n); 44 else if(n%10==2&&n%100!=12&&n!=12) 45 printf("The %dnd humble number is ",n); 46 else if(n%10==3&&n%100!=13&&n!=13) 47 printf("The %drd humble number is ",n); 48 else printf("The %dth humble number is ",n); 49 printf("%lld.\n",s[n-1]); 50 } 51 return 0; 52 }
A - Humble Numbers,布布扣,bubuko.com
原文:http://www.cnblogs.com/angledamon/p/3894174.html