当前位置:网站首页>1082 read number in Chinese (25 points)
1082 read number in Chinese (25 points)
2022-06-30 14:55:00 【Xue Dongjing】
1082 Read Number in Chinese (25 branch )
The question
Give an integer , It is required to output its Chinese pronunciation .
Such as “-123456789” pronounce as “Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu”
“100800” pronounce as “yi Shi Wan ling ba Bai”
Ideas
simulation , Because the number of digits is very small , It can be solved directly . Divide the numbers into three groups
A bit to a thousand | Tens of thousands to tens of millions | Billion
It can be read as a single digit to a thousand digit . Determine the relative position of each group , The first set of direct outputs , Add ten thousand at the end of the second group , Add a hundred million to the third group .
Note the ‘0’, Zeros at the end of a group are not read , Connected zeros read only one . Be careful 0 The number of , Note blank space .
Code
#include<stdio.h>
#include<string.h>
char figure[12][10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
char weight[12][10]={"","Shi","Bai","Qian","Wan","Yi"};
int main()
{
char number[20];
int len,star=0,flag=0;
scanf("%s",number);
len=strlen(number);
if(len==1&&number[0]=='0'){
printf("ling");
}else{
if(number[0]=='-'){
printf("Fu ");
star=1;
len-=1;
}
for(int i=star;i<star+len;i++){
if(i!=star&&number[i]!='0'){
printf(" ");
}
if(number[i]!='0'){
if(flag!=0){
printf("ling ");
flag=0;
}
printf("%s",figure[number[i]-'0']);
flag=0;
if((star+len-i-1)%4!=0){
printf(" %s",weight[(star+len-i-1)%4]);
}
}else{
if(flag==0){
// printf("ling");
flag++;
}
}
if((star+len-i)%4==1&&star+len-i>4){
printf(" %s",weight[(star+len-i)/4+3]);
flag=0;
}
}
}
return 0;
}
边栏推荐
- Knowledge learned from the water resources institute project
- 2021 geek challenge Web
- 1148 werewolf - Simple Version (20 points)
- catkin_ Make reports an error, transfers the location of the workspace, and uses other people's workspace files to cause compilation errors
- [buuctf] [actf2020 freshman competition]include
- [buuctf] [geek challenge 2019] secret file
- Average and maximum values of MATLAB matrix
- Summary of C language interview questions
- day02
- Distributed -- openresty+lua+redis
猜你喜欢

CCF drawing (full mark code + problem solving ideas + skill summary) February 2, 2014

CCF elimination games (Full Score code + problem solving ideas + skill summary) February 2, 2015

Querywrapper in mybaits plus

CCF numerical sorting (Full Score code + problem solving ideas + skill summary) 201503-2
![[buuctf] [actf2020 freshman competition]exec1](/img/af/22051a5feb3c1f6d7201a483bde127.jpg)
[buuctf] [actf2020 freshman competition]exec1

PS tip: the video frame to Layer command cannot be completed because dynamiclink is not available

Matlab construction operation example
![【BUUCTF】[GXYCTF2019]Ping Ping Ping1](/img/dc/4d87dfb0c2fa9cd75b54e092fd3971.jpg)
【BUUCTF】[GXYCTF2019]Ping Ping Ping1

PS dynamic drawing

【BUUCTF】 EasySql
随机推荐
Error $(...) size is not a function
Double pointer letter matching
1136: password translation
Vue returns to the previous page without refreshing the page / Vue caches the page
Double pointer palindrome string
CCF call auction (full mark code + problem solving ideas + skill summary) 201412 - 3
Matlab finds a prime number that is greater than a given integer and follows this integer
JS to realize simple lottery function
Finding the median of two arrays by dichotomy
数控加工中心打刀缸工作原理及故障处理
Text matching - [naacl 2021] augsbert
2021-07-14 mybaitsplus
1132: stone scissors cloth
[extensive reading of papers] sentimental analysis of online reviews with a hierarchical attention network
Database connection to company database denied
PS cutting height 1px, Y-axis tiling background image problem
Using member variables and member functions of a class
1131: genetic correlation
val_ Loss decreases first and then increases or does not decrease but only increases
[extensive reading of papers] attributes guided facial image completion