当前位置:网站首页>可怜小凡(模拟)
可怜小凡(模拟)
2022-07-17 05:21:00 【winkiii】
描述
小凡的老师给了小凡一个任务就是做一个中文的计算器。比如说输入“十加十”,那么小凡就要得到 20 这个值,但是小凡太笨怎么都搞不定,所以老师给他降低了要求,让他只要把阿拉伯数字转换成中文就行了,还说如果他连这个都不会就不给他及格了。小凡都快哭了,好心的你帮帮他吧。
输入
有多组测试数据,请用while(…)读入数据,直到EOF。
每组数据为一串数字,如:2358、2989、51(不超过9999)。
输出
每个输入对应一个输出。对应上面的输出分别为二千三百五十八、两千九百八十九、五十一。
输入样例 1
36
211
2126
10
20
101
输出样例 1
三十六
二百一十一
二千一百二十六
十
二十
一百零一
#include<stdio.h>
int change(int n){
char c[11][20] = {
"零","一","二","三","四","五","六","七","八","九"};
int i=0,j,k,p,m,count=0;
int a[10000];
if(n==0) printf("零");
if(n==10) printf("十");
m = n;
while(n>0 && m!=10){
a[i] = n%10;
if(a[i]==0){
count++;
}
i++;
n /= 10;
}
for(j=i-1;j>=0;j--){
p=j-1;
printf("%s",c[a[j]]);
if(j==1){
printf("十");
if(a[p]==0){
break;
}
}
else if(j==2){
printf("百");
if(count==2){
break;
}
else if(count==1 && a[j-1]==0){
printf("零%s",c[a[j-2]]);
break;
}
}
else if(j==3){
printf("千");
if(count==3){
break;
}
else if(count==2 && a[j-3]!=0){
printf("零%s",c[a[j-3]]);
break;
}
else if(count==2 && a[j-2]!=0){
printf("零%s十",c[a[j-2]]);
break;
}
else if(count==1 && a[j-1]==0){
printf("零%s十%s",c[a[j-2]],c[a[j-3]]);
break;
}
}
}
printf("\n");
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
change(n);
}
}
边栏推荐
- Talk about Zhongtai: my understanding and thinking about Zhongtai
- 小迪网络安全笔记-信息收集-架构、搭建、waf(8)
- From entering URL to displaying page
- Generate audio and waveform in PWM and DAC exercises of stm32
- 5-17 hidden student services of Shaanxi University of science and technology
- Double code time scale network diagram
- @resource is popular in idea
- Restapi implementation of automatic completion & case implementation (search box input for automatic completion)
- Causes and solutions of over fitting
- Share the application cases of CS brand patch T card in the field of hunting camera
猜你喜欢
![[jmeter] TCP Sampler](/img/ac/3b08db8808d84eb144262d78880050.png)
[jmeter] TCP Sampler

Learning about STM assembler design

Talk about Zhongtai: my understanding and thinking about Zhongtai

5-17 hidden student services of Shaanxi University of science and technology

基于SPI/IIC接口的OLED数据显示

管理员阻止运行此应用

Full experience of soft examination at the beginning, middle and advanced levels

STM32的PWM和DAC练习中生成音频和波形

Spot detection record

聊聊中台:我对中台的一些理解与思考
随机推荐
Network layer and IP learning
管理员阻止运行此应用
简单irules编写 入门级
Why do solution providers "love" CS Genesis SD NAND
Share the successful cooperation between CS brand sdnand and wearable devices
OLED data display based on spi/iic interface
What is data center?
渣渣学习之路(1)输出某年某月的日历页
小迪网络安全-笔记(2)
STM32 serial communication related learning
Performance comparison between merge into and update in Oracle
Hand in hand building a home NAS universal server (1) | configuration selection and preparation
wireshark抓包:错误分析
Slag learning path (1) output the calendar page of a certain month of a certain year
Tcp/ip protocol learning
Preparation of blast Library of rust language from scratch (1) -- Introduction to the basics of blas
wireshark抓包:报文信息
小迪网络安全-笔记 加密编码算法(6)
总价合同、成本补偿合同、工料合同
常见的用户密码加密方式以及破解方法