当前位置:网站首页>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;
}
边栏推荐
- 高清机械原理 · 机械设计经典动图
- Hbuilder most commonly used and full shortcut key set
- [extensive reading of papers] multi modal sarcasm detection and human classification in code mixed conversations
- CCF window (Full Score code + problem solving idea) March 2, 2014
- 2021-07-15Caused by: org. quartz. ObjectAlreadyExistsException: Unable to store Job : ‘DEFAULT. TASK_ 1‘
- CCF image rotation (Full Score code + problem solving idea) 201503-01
- 1132: stone scissors cloth
- 1134: Legal C identifier query
- 1136: password translation
- [extensive reading of papers] sentimental analysis of online reviews with a hierarchical attention network
猜你喜欢
ThinkPHP v3.2 comment annotation injection write shell
CCF call auction (full mark code + problem solving ideas + skill summary) 201412 - 3
ThinkPHP show method parameter controllable command execution
CCF image rotation (Full Score code + problem solving idea) 201503-01
Solve the problem that codeblocks20.03 on win11 cannot run for the first time
Matlab function for limit, definite integral, first-order derivative, second-order derivative (classic examples)
Win10 one click Reset win10 to solve all system bugs without deleting any files and Applications
@PathVariable
Shangpinhui knowledge points of large e-commerce projects
How to realize selective screen recording for EV screen recording
随机推荐
Knowledge learned from the water resources institute project
Bucket sorting (C language)
After the MySQL service on the local computer is started and stopped, some services will automatically stop when they are not used by other services or programs
[buuctf] [actf2020 freshman competition]include
Vue returns to the previous page without refreshing the page / Vue caches the page
Color classification of sorting
Win10 backup backup shows that creating a shared protection point on the shadow failed
The kth largest element in the sorted array
Add attributes to multimode
1150 traveling salesman problem (25 points)
Programming exercises: special numbers (problem solving ideas + code implementation)
1107 social clusters (30 points)
2021-05-12
2021-07-15Caused by: org. quartz. ObjectAlreadyExistsException: Unable to store Job : ‘DEFAULT. TASK_ 1‘
Sorting by character frequency
ctfshow nodejs
V3 02——What‘s new in Chrome extensions
Clear the route cache in Vue
Binary rotation array (2)
1025 pat ranking (25 points)