实在是无语了,为什么在zoj已经ac的代码在hdu是wa啊!
看过之后,发现这里的n和cnt只能用int,或许hdu对数据的格式控制的比较严格吧!
#include <stdio.h>
#include<stdlib.h>
#define MAX 2000000000
long long a[5842];
int cmp(const void * x, const void *y)
{
if( *(int*)x > *(int*)y ) return 1;
else return -1;
}
int main(void)
{
long long i, j, k, l, t;
int n,cnt=0;
for(i = 1; i <= MAX; i *= 2){
for(j = 1; j <= MAX; j*= 3){
if(i*j > MAX) break;
for(k = 1; k <= MAX; k *= 5){
if(i*j*k > MAX) break;
for(l = 1; l <= MAX; l *= 7){
if((t = i*j*k*l) <= MAX){
a[cnt++] = t;
}
}
}
}
}
qsort(a, 5842, sizeof(long long), cmp);
while (scanf("%lld", &n) != EOF && n){
if(n % 10 == 1 && n % 100 != 11)
printf("The %dst humble number is %lld.\n", n, a[n-1]);
else if(n % 10 == 2 && n % 100 != 12)
printf("The %dnd humble number is %lld.\n", n, a[n-1]);
else if(n % 10 == 3 && n % 100 != 13)
printf("The %drd humble number is %lld.\n", n, a[n-1]);
else printf("The %dth humble number is %lld.\n", n, a[n-1]);
}
return 0;
}