当前位置:网站首页>可怜小凡(模拟)
可怜小凡(模拟)
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);
}
}
边栏推荐
猜你喜欢

mass data

吴恩达机器学习第14-15章

【自动化测试】——robotframework实战(二)新建测试用例

Programming learning based on ardunio ide software development

Hand in hand building a home NAS universal server (1) | configuration selection and preparation

ARM开发环境入门

Pytorch deep learning practice-b station Liu erden-day6

Face recognition error

伺服电机的电子齿轮比如何确定?

Talk about Zhongtai: my understanding and thinking about Zhongtai
随机推荐
BigDecimal中divide方法
Wu Enda machine learning chapter 10-11
OpenSSL---堆栈
C language structure array pointer and function
ANAME
企业数据治理之勒索病毒篇
管理员阻止运行此应用
️️固高运动控制卡的相关知识点
Full experience of soft examination at the beginning, middle and advanced levels
聊聊中台:我对中台的一些理解与思考
高并发day04(ZAB协议,观察者,nc,AVRO,RPC)
Depth first search (DFS for short)
Technical specification for secure electronic signature and password gm/t 0031 | GB / T 38540 format OpenSSL package analysis
redis
Restapi implementation of automatic completion & case implementation (search box input for automatic completion)
Tcp/ip protocol learning
5-17 hidden student services of Shaanxi University of science and technology
小迪网络安全-笔记 加密编码算法(6)
No application for domain name SSL certificate under ports 80 and 443 (applicable to acme.sh and certbot)
lock