当前位置:网站首页>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;
}
边栏推荐
- CCF string matching (Full Score code + problem solving ideas + skill summary) March 3, 2014
- 2021 geek challenge Web
- Vue returns to the previous page without refreshing the page / Vue caches the page
- ThinkPHP v3.2 comment annotation injection write shell
- jsPlumb. Deleteeveryconnection is not a function & jsplumb clear canvas jsplumb delete all nodes and all connections
- Steps for commissioning of vertical machining center
- Color classification of sorting
- [extensive reading of papers] multimodal joint attribute prediction and value extraction for e-commerce product
- Matlab function for limit, definite integral, first-order derivative, second-order derivative (classic examples)
- [extensive reading of papers] analyzing connections between user attributes, images, and text
猜你喜欢

Error $(...) size is not a function

Lihongyi machine learning 2020 homework summary

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

How does hbuilder display in columns?

ES6 notes

day02

August 24, 2021 deque queue and stack

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

2021-07-14 mybaitsplus
![[buuctf] [actf2020 freshman competition]include](/img/42/50439290177fdea5f431e315cac1a1.jpg)
[buuctf] [actf2020 freshman competition]include
随机推荐
How to realize selective screen recording for EV screen recording
浅析卧式加工中心上不规则台阶孔存在问题
Matlab to find prime pairs within 100
【BUUCTF】 Have Fun
Matlab function for limit, definite integral, first-order derivative, second-order derivative (classic examples)
Shangpinhui knowledge points of large e-commerce projects
CCF numerical sorting (Full Score code + problem solving ideas + skill summary) 201503-2
Matlab finds prime numbers within 100
Minimum covering substring of two pointers
2021-05-12
Double pointer palindrome string
V3_ Chrome extended Chinese translation document V3 directory
Error $(...) size is not a function
[buuctf] [actf2020 freshman competition]include
2021 geek challenge Web
PS cutting height 1px, Y-axis tiling background image problem
Distributed -- openresty+lua+redis
2021-08-05 leetcode notes
The first dark spring cup dnuictf
Win10 backup backup shows that creating a shared protection point on the shadow failed