栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1095 Humble Numbers

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1095 Humble Numbers

#include <stdio.h>#include <string.h>#include <iostream>using namespace std;int c2,c3,c5,c7;int min(int a,int b,int c,int d){    if(a<=b&&a<=c&&a<=d)    {        c2++;        return a;    }    if(b<=a&&b<=c&&b<=d)    {        c3++;        return b;    }    if(c<=b&&c<=a&&c<=d)    {        c5++;        return c;    }    if(d<=b&&d<=c&&d<=a)    {        c7++;        return d;    }}int main(void){    c2=c3=c5=c7=1;    int num[5847];    num[1] = 1;    int count =1;    while(count<=5843)    {        count++;        num[count]=min(2*num[c2],3*num[c3],5*num[c5],7*num[c7]);        if(num[count] == 2*num[c2]) c2++;        if(num[count] == 3*num[c3]) c3++;        if(num[count] == 5*num[c5]) c5++;        if(num[count] == 7*num[c7]) c7++;    }int n;while(cin>>n){    if(!n) break;    printf("The %d",n);    if(n%100/10==1) printf("th humble number is %d.n",num[n]);        else if(n%10==1)        { printf("st humble number is %d.n",num[n]);        }        else if(n%10==2)        { printf("nd humble number is %d.n",num[n]);        }        else if(n%10==3)        { printf("rd humble number is %d.n",num[n]);        }        else        { printf("th humble number is %d.n",num[n]);        }}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/380150.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号