HDU 1058

来源:互联网 发布:量化数据分析 pdf 编辑:程序博客网 时间:2024/04/29 02:08

英语很重要……


#include "stdio.h"#define MIN(a, b) ((a)>(b)?(b):(a))#define MIN_FOUR(a, b, c, d) MIN(MIN(a,b), MIN(c, d))long humble[5842];void cal(){int i;int pos1, pos2, pos3, pos4;long na, nb, nc, nd;humble[0] = 1;pos1 = pos2 = pos3 = pos4 = 0;for(i=1; i<=5842; i++){humble[i] = MIN_FOUR( na=humble[pos1]*2, nb=humble[pos2]*3, nc=humble[pos3]*5, nd=humble[pos4]*7 );if(humble[i]==na) pos1++;if(humble[i]==nb) pos2++;if(humble[i]==nc) pos3++;if(humble[i]==nd) pos4++;}}void main(){int n;cal();while(scanf("%d", &n), n){printf("The %d", n);if(n%100!=11&&n%10==1) printf("st");else if(n%100!=12&&n%10==2) printf("nd");else if(n%100!=13&&n%10==3) printf("rd");else printf("th");printf(" humble number is %d.\n", humble[n-1]);}}


原创粉丝点击