通过此题有两个收获:
第一-----------------序数词的正确拼写。
第二----------------学会了map的基本使用方法。
---------------------------------------------------------------------------------------------------------------KeeP MoVing .............
1 #include<stdio.h> 2 3 #include<string.h> 4 #include<queue> 5 #include<map> 6 #include<algorithm> 7 using namespace std; 8 #define max 5842+10 9 10 int h[max]={0,1}; 11 int a[]={2,3,5,7}; 12 typedef long long LL; 13 14 void init(){ 15 priority_queue<LL,vector<LL>,greater<LL> > q; 16 map<LL,bool> vis; 17 for(int i=0;i<4;i++){ 18 q.push(a[i]); 19 } 20 int cnt=2; 21 while(cnt<=5842){ 22 LL now=q.top(); q.pop(); 23 h[cnt++]=now; 24 for(int i=0;i<4;i++){ 25 LL temp=now*a[i]; 26 if(!vis[temp]){ 27 vis[temp]=true; 28 q.push(temp); 29 } 30 } 31 } 32 } 33 34 int main(){ 35 init(); 36 int n; 37 while(~scanf("%d",&n),n){ 38 if(n%10==1&&n%100!=11){ 39 printf("The %dst humble number is %d.",n,h[n]); 40 } 41 else if(n%10==2&&n%100!=12){ 42 printf("The %dnd humble number is %d.",n,h[n]); 43 } 44 else if(n%10==3&&n%100!=13){ 45 printf("The %drd humble number is %d.",n,h[n]); 46 } 47 else{ 48 printf("The %dth humble number is %d.",n,h[n]); 49 } 50 puts(""); 51 } 52 }