第二次HDOJ:1058

AC代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

#define Max 5845

long long int final[Max];

int main(void)
{
    int count = 1;
    final[1] = 1;
    int factor2 = 1, factor3 = 1, factor5 = 1, factor7 = 1;
    long long int compare1, compare2, compare;
    while(count != 5842)
    {        
        compare1 = min(final[factor2] * 2, final[factor3] * 3);
        compare2 = min(final[factor5] * 5, final[factor7] * 7);
        compare = min(compare1, compare2);
        if(compare == final[factor2] * 2)  factor2++;
        if(compare == final[factor3] * 3)  factor3++;
        if(compare == final[factor5] * 5)  factor5++;
        if(compare == final[factor7] * 7)  factor7++;
        final[++count] = compare;
    }
    
    freopen("in.txt","r",stdin);
    int n;
    while(scanf("%d",&n) && n)
    {
            if(n%10==1&&n%100!=11)
                printf("The %dst humble number is %lld.\n", n, final[n]);
            else if(n%10==2&&n%100!=12)
                printf("The %dnd humble number is %lld.\n", n, final[n]);
            else if(n%10==3&&n%100!=13)
                printf("The %drd humble number is %lld.\n", n, final[n]);
            else
                printf("The %dth humble number is %lld.\n", n, final[n]);
    }
    
    fclose(stdin);
    system("pause");
    return 0;
}

 

posted @ 2018-10-28 20:12  pha创噬  阅读(104)  评论(0编辑  收藏  举报