【HDOJ】1058 Humble Numbers

简单题,注意打表,以及输出格式。这里使用了可变参数。

 #include <stdio.h>

 #define MAXNUM 5845
#define ANS 2000000000 int buf[MAXNUM];
int min(int a, int b) {
return a<b ? a:b;
} int minn(int argc, ...) {
int i, tmp;
int *arg = &argc + ; tmp = *arg;
for (i=; i<argc; ++i)
tmp = min(tmp, *++arg); return tmp;
} int main() {
int i;
int a, b, c, d;
int ia, ib, ic, id;
ia = ib = ic = id = ; i = ;
buf[] = ; a = * buf[ia];
b = * buf[ib];
c = * buf[ic];
d = * buf[id];
while (buf[i] < ANS) {
buf[++i] = minn(, a,b,c,d);
if (buf[i] == a) a = *buf[++ia];
if (buf[i] == b) b = *buf[++ib];
if (buf[i] == c) c = *buf[++ic];
if (buf[i] == d) d = *buf[++id];
} while (scanf("%d", &i)!=EOF && i) {
if (i%== && i%!=)
printf("The %dst humble number is %d.\n", i, buf[i]);
else if (i%== && i%!=)
printf("The %dnd humble number is %d.\n", i, buf[i]);
else if (i%== && i%!=)
printf("The %drd humble number is %d.\n", i, buf[i]);
else
printf("The %dth humble number is %d.\n", i, buf[i]);
} return ;
}
上一篇:javascript url几种编码方式


下一篇:TCP/IP 协议 ----- 协议栈