您的位置:首页 > 其它

POJ 2247

2015-06-10 17:12 267 查看
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
int min_4(int a,int b,int c,int d)
{
a=a<b?a:b;
a=a<c?a:c;
a=a<d?a:d;
return a;
}
string work(int x)
{
string s="th";
const string ss[3]={"st","nd","rd"};
int t=x%10;
if(t==1&&x%100!=11)s=ss[0];
else if(t==2&&x%100!=12)s=ss[1];
else if(t==3&&x%100!=13)s=ss[2];
return s;
}
int main()
{
//freopen("acm.acm","r",stdin);
int n,len,i,t,m;
len=1;
int a[6000],x2=0,x3=0,x5=0,x7=0;
a[0]=1;
while(len <= 5846)
{
m=min_4(a[x2]*2,a[x3]*3,a[x5]*5,a[x7]*7);
if(m==a[x2]*2)x2++;
if(m==a[x3]*3)x3++;
if(m==a[x5]*5)x5++;
if(m==a[x7]*7)x7++;
a[len++]=m;
}
while(scanf("%d",&n))
{
if(!n)
break;
string s=work(n);
printf("The ");
printf("%d",n);
printf("%s",s.c_str());
printf(" humble number is ");
printf("%d",a[n-1]);
printf(".\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: