1. 程式人生 > >HDU 1058 Humble Numbers

HDU 1058 Humble Numbers

for n) clas define clu def else while n-1

註意輸出有點坑,只特判個位1 2 3輸出格式是不對的,還要註意十位不能為1,比如112 111後邊都是th而不是nd st,就這一點坑的地方

#include <bits/stdc++.h>
using namespace std;
#define LL long long
LL a[6000];
int len;
void dabiao()
{
     len=0;
    LL i,j,k,l;
    for(i=1;i<=2000000000;i*=2)
    {
       // a[len++]=i;
        //printf("%lld****\n",a[len-1]);
        for
(j=1;j*i<=2000000000;j*=3) { //a[len++]=j*i; for(k=1;j*i*k<=2000000000;k*=5) { //a[len++]=j*i*k; for(l=1;j*i*k*l<=2000000000;l*=7) a[len++]=i*j*k*l; //printf("************\n"); } } } sort(a,a
+len); } int main() { int n,i,m; dabiao(); //sort() while(scanf("%d",&n),n) { printf("The %d",n); m=n/10%10;//十位不能為1,eg:11 12 13 111 112 113,,, if(n%10==1&&m!=1) printf("st "); else if(n%10==2&&m!=1) printf("nd ");
else if(n%10==3&&m!=1) printf("rd "); else printf("th "); printf("humble number is %d.\n",a[n-1]); } }

HDU 1058 Humble Numbers