数的读法c语言程序,[蓝桥杯][基础练习VIP]数的读法 (C语言代码)

解题思路: 这题用这个残缺不全的代码能AC我都不敢相信自己的眼睛QWQ

注意事项:

参考代码:#include 

char s[12][5] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu","shi"};

long long temp;

void f(long long n,long long m,int k){

if(n == 0){

if(k == 11) //十亿位

printf("shi ");

return;

}

else{

f(n/10,m*10,k+1);

if(k == 9){ //亿位

if(n%10 != 0)

printf("%s yi ", s[n%10]);

}

if(k == 8){ //千万位

if(n%10 != 0)

printf("%s qian ", s[n%10]);

}

if(k == 7){ //百万位

if(n%10 != 0)

printf("%s bai ", s[n%10]);

}

if(k == 6){ //十万位

if(n%10 == 1)

printf("shi ");

else if(n%10 != 0)

printf("%s shi ", s[n%10]);

else if(n%10 == 0)

printf("ling ");

}

if(k == 5){ //万位

if(n%10 != 0)

printf("%s wan ", s[n%10]);

else if(temp%10 != 0 && temp/10%10 != 0 && temp/100%10 == 0 && temp/1000%10 == 0 && temp/10000%10 == 0)

printf("wan ling ");

else if(n%10 == 0)

printf("wan ");

}

if(k == 4){ //千位

if(n%10 != 0)

printf("%s qian ", s[n%10]);

else if(temp%10 != 0 && temp/10%10 != 0 && temp/100%10 == 0 && temp/1000%10 == 0 && temp/10000%10 != 0)

printf("ling ");

else if(temp%10 == 0 && temp/10%10 == 0 && temp/100%10 != 0 && temp/1000%10 == 0 && temp/10000%10 != 0)

printf("ling ");

}

if(k == 3){ //百位

if(n%10 != 0)

printf("%s bai ", s[n%10]);

else if(temp%10 != 0 && temp/10%10 != 0 && temp/100%10 == 0 && temp/1000%10 != 0)

printf("ling ");

else if(temp%10 == 0 && temp/10%10 != 0 && temp/100%10 == 0 && temp/1000%10 != 0)

printf("ling ");

}

if(k == 2){ //十位

if(temp%10 == 0 && temp/10%10 != 0 && temp/100%10 == 0 && temp/1000%10 != 0)

printf("%s shi", s[n%10]);

else if(temp%10 == 0 && temp/10%10 != 0 && temp/100%10 != 0)

printf("%s shi ", s[n%10]);

else if(temp%10 != 0 && temp/10%10 != 0 && temp/100%10 != 0)

printf("%s shi ", s[n%10]);

else if(temp%10 == 0 && temp/10%10 == 1)

printf("shi ");

else if(temp%10 == 0 && temp/10%10 >= 2)

printf("%s shi ", s[n%10]);

else if(temp%10 != 0 && temp/10%10 == 1)

printf("shi ");

else if(temp%10 != 0 && temp/10%10 >= 2)

printf("%s shi ", s[n%10]);

else if(temp%10 != 0 && temp/10%10 == 0)

printf("ling ");

}

if(k == 1){ //个位

if(n%10 != 0)

printf("%s ", s[n%10]);

}

}

}

int main(){

long long n;

scanf("%lld", &n);

temp = n;

f(n,1,1);

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于一个n,我们可以将其拆分成若干组位相同的字,然后读出每一组字的值和单位。例如: - 对于 123456789,我们可以将其拆分成 1 亿,2345 万,6789。 - 对于 200000,我们可以将其拆分成 2 十万。 具体的读法可以参考以下规则: - 对于 1~9 的字,直接读出其汉字,如 1 读作“一”,9 读作“九”。 - 对于 10~99 的字,读出十位的汉字,如果个位不为 0,则加上个位的汉字,如 22 读作“二十二”,55 读作“五十五”。 - 对于 100~999 的字,读出百位的汉字,如果十位为 0,则只读出“几百”,否则在“几百”后加上十位和个位的汉字,如 234 读作“二百三十四”,707 读作“七百零七”。 - 对于 1000~9999 的字,读出千位的汉字,如果百位为 0,则只读出“几千”,否则在“几千”后加上百位、十位和个位的汉字,如 5678 读作“五千六百七十八”。 - 对于 10000~99999 的字,读出万位的汉字,如果千位为 0,则只读出“几万”,否则在“几万”后加上千位、百位、十位和个位的汉字,如 12345 读作“一万二千三百四十五”。 - 对于 100000~999999 的字,读出十万位的汉字,如果万位为 0,则只读出“几十万”,否则在“几十万”后加上万位、千位、百位、十位和个位的汉字,如 234567 读作“二十三万四千五百六十七”。 - 对于 1000000~99999999 的字,读出百万位的汉字,如果十万位为 0,则只读出“几百万”,否则在“几百万”后加上十万位、万位、千位、百位、十位和个位的汉字,如 12345678 读作“一千二百三十四万五千六百七十八”。 - 对于 100000000~999999999 的字,读出亿位的汉字,如果百万位为 0,则只读出“几亿”,否则在“几亿”后加上百万位、十万位、万位、千位、百位、十位和个位的汉字,如 987654321 读作“九亿八千七百六十五万四千三百二十一”。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值