鱼C论坛

 找回密码
 立即注册
查看: 1410|回复: 6

[已解决]c++输入整数输出对应中文的题目怎么解

[复制链接]
发表于 2021-10-15 23:02:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
预期结果:请帮忙解一下这题,如果能附加注释是最好的了,谢谢,新手上路
Problem Description
给出在[0, 100]范围内的整数数字,你能把对应的中文写出来吗?
Input
第一行输入一个T (T <= 20),后面每行一个数字,题目保证数字是[0, 100]。
Output
第一行输入一个T (T <= 20),后面每行一个数字,题目保证数字是[0, 100]。
Sample Input
5
1
22
3
4
100
Sample Output

二十二


一百
最佳答案
2021-10-16 09:21:41
  1. #include <stdio.h>

  2. int main(){
  3.     int num;
  4.     char* digit[12] = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}; //存入所有中文字符,方便等下输出
  5.     scanf("%d", &num);
  6.    
  7.     if(num <= 10) printf("%s", digit[num]); // 当整数小于等于 10(1, 2, 3 .... 10)
  8.     else if(num < 20) printf("十%s", digit[num%10]); // 当整数小于 20(11, 12, 13 .... 19)
  9.     else if(num < 100){ // 当整数小于 100(20, 21, 22 .... 99)
  10.         int a = num%10; // 取个位数
  11.         int b = (num - a)/10; // 取十位数
  12.         if(!(a)) printf("%s%s", digit[b], digit[10]); // 当个位数为 0
  13.         else printf("%s%s%s", digit[b], digit[10], digit[a]); // 当个位数不是 0
  14.     }
  15.     else printf("一百"); // 当整数为 100 整
  16.    
  17.     return 0;
  18. }
复制代码
  1. 12
  2. 十二

  3. 9


  4. 34
  5. 三十四

  6. 100
  7. 一百
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-10-16 09:21:41 | 显示全部楼层    本楼为最佳答案   
  1. #include <stdio.h>

  2. int main(){
  3.     int num;
  4.     char* digit[12] = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}; //存入所有中文字符,方便等下输出
  5.     scanf("%d", &num);
  6.    
  7.     if(num <= 10) printf("%s", digit[num]); // 当整数小于等于 10(1, 2, 3 .... 10)
  8.     else if(num < 20) printf("十%s", digit[num%10]); // 当整数小于 20(11, 12, 13 .... 19)
  9.     else if(num < 100){ // 当整数小于 100(20, 21, 22 .... 99)
  10.         int a = num%10; // 取个位数
  11.         int b = (num - a)/10; // 取十位数
  12.         if(!(a)) printf("%s%s", digit[b], digit[10]); // 当个位数为 0
  13.         else printf("%s%s%s", digit[b], digit[10], digit[a]); // 当个位数不是 0
  14.     }
  15.     else printf("一百"); // 当整数为 100 整
  16.    
  17.     return 0;
  18. }
复制代码
  1. 12
  2. 十二

  3. 9


  4. 34
  5. 三十四

  6. 100
  7. 一百
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2021-10-16 20:41:49 | 显示全部楼层
file:///C:/Users/%E9%98%BF%E9%A3%9E%E5%93%A5/Desktop/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20211016202139.png
你好能帮我再看看吗,拿去Oj上提交显示的是Compilation Error 编译错误,谢谢您了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-10-16 20:44:45 | 显示全部楼层

file:///C:/Users/%E9%98%BF%E9%A3%9E%E5%93%A5/Desktop/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20211016202139.png
你好,能再帮我看一下吗,我提交到OJ上,是面显示Compilation Error 编译错误,谢谢了,上面是我发给您 的图片地址
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-10-16 20:56:04 | 显示全部楼层
提交习题最好自己做比较好,如果只是不明白可以发问不明白部分,不是全部哦
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-10-16 21:13:18 | 显示全部楼层

上面给出的是这样子的信息
2_37884_3662015_24779.c: In function 'main':
2_37884_3662015_24779.c:5:91: error: expected expression before '/' token
     char* digit[12] = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}; //存入所有中文字符,方便等下输出
                                                                                           ^
2_37884_3662015_24779.c:5:91: error: stray '\264' in program
2_37884_3662015_24779.c:5:91: error: stray '\346' in program
2_37884_3662015_24779.c:5:91: error: stray '\310' in program
2_37884_3662015_24779.c:5:91: error: stray '\353' in program
2_37884_3662015_24779.c:5:91: error: stray '\313' in program
2_37884_3662015_24779.c:5:91: error: stray '\371' in program
2_37884_3662015_24779.c:5:91: error: stray '\323' in program
2_37884_3662015_24779.c:5:91: error: stray '\320' in program
2_37884_3662015_24779.c:5:91: error: stray '\326' in program
2_37884_3662015_24779.c:5:91: error: stray '\320' in program
2_37884_3662015_24779.c:5:91: error: stray '\316' in program
2_37884_3662015_24779.c:5:91: error: stray '\304' in program
2_37884_3662015_24779.c:5:91: error: stray '\327' in program
2_37884_3662015_24779.c:5:91: error: stray '\326' in program
2_37884_3662015_24779.c:5:91: error: stray '\267' in program
2_37884_3662015_24779.c:5:91: error: stray '\373' in program
2_37884_3662015_24779.c:5:91: error: stray '\243' in program
2_37884_3662015_24779.c:5:91: error: stray '\254' in program
2_37884_3662015_24779.c:5:91: error: stray '\267' in program
2_37884_3662015_24779.c:5:91: error: stray '\275' in program
2_37884_3662015_24779.c:5:91: error: stray '\261' in program
2_37884_3662015_24779.c:5:91: error: stray '\343' in program
2_37884_3662015_24779.c:5:91: error: stray '\265' in program
2_37884_3662015_24779.c:5:91: error: stray '\310' in program
2_37884_3662015_24779.c:5:91: error: stray '\317' in program
2_37884_3662015_24779.c:5:91: error: stray '\302' in program
2_37884_3662015_24779.c:5:91: error: stray '\312' in program
2_37884_3662015_24779.c:5:91: error: stray '\344' in program
2_37884_3662015_24779.c:5:91: error: stray '\263' in program
2_37884_3662015_24779.c:5:91: error: stray '\366' in program
2_37884_3662015_24779.c:8:45: error: expected expression before '/' token
     if(num <= 10) printf("%s", digit[num]); // 当整数小于等于 10(1, 2, 3 .... 10)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-10-16 23:22:45 | 显示全部楼层
傻眼貓咪 发表于 2021-10-16 20:56
提交习题最好自己做比较好,如果只是不明白可以发问不明白部分,不是全部哦

嗯嗯好的谢谢您了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-6-3 03:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表