Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
输出格式好恶心,WA了2次,总算过了#define N 5843 using namespace std; int h[N]; char suffix[10][3] = {"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"}; int main() { int i2, i3, i5, i7, n; h[1] = i2 = i3 = i5 = i7 = 1; for(int i=2; i<N; ++i) { h[i] = min(min(h[i2]*2, h[i3]*3), min(h[i5]*5, h[i7]*7)); if(h[i] == h[i2]*2) ++i2; if(h[i] == h[i3]*3) ++i3; if(h[i] == h[i5]*5) ++i5; if(h[i] == h[i7]*7) ++i7; } while(scanf("%d", &n)!=EOF && n!=0) printf("The %d%s humble number is %d.\n", n, (n%100>=11&&n%100<=13)?"th":suffix[n%10], h[n]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator