Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

输出格式好恶心,WA了2次,总算过了

Posted by makuiyu at 2014-01-13 13:57:52 on Problem 2247
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator