当前位置:网站首页>7-23 currency conversion (using array conversion)
7-23 currency conversion (using array conversion)
2022-07-03 14:14:00 【Big fish】
Enter an integer ( The number of digits does not exceed 9 position ) Represents a RMB value ( The unit is yuan ), Please convert to the capital Chinese format required by the financial department . Such as 23108 element , Transformed into “ Twenty three thousand one hundred and eight ” element . To simplify the output , In lowercase a-j The order represents capital numbers 0-9, use S、B、Q、W、Y Each represents ten 、 hundred 、 Thousand 、 ten thousand 、 Billion . therefore 23108 The element should be converted to output “cWdQbBai” element .
Input format :
The input gives no more than 9 A nonnegative integer of bits .
Output format :
Output the converted result in one line . Be careful “ zero ” The usage of must conform to Chinese habits .
sample input 1:
813227345
sample output 1:
iYbQdBcScWhQdBeSf
sample input 2:
6900
sample output 2:
gQjBSolution 1 :
#include <stdio.h>
int main()
{
int i=0,j,n;
scanf("%d",&n);
char a[9];
char b[9]={'\n','S','B','Q','W','S','B','Q','Y'}; // The names of bits are stored in the array b
if(n==0){
printf("a\n");
} else{
while(n!=0){ // Numbers are stored in arrays a
a[i]=n%10;
n=n/10;
i++;
}
i=i-1;
for(;i>=0;i--){ // Array a Reverse output
if(a[i]==0){
if(i==4){ // Wan Weiwei 0 The situation of
if(a[8]!=0 && a[7]+a[6]+a[5]+a[4]==0 ){ // There are 100 million , And all ten thousand bits are zero
printf("a"); // Output a zero ( Such as 100004800)
}else{
printf("W"); // No, if there are ten thousand bits on the side, one ten thousand will be output .
}
}else{
if(a[i-1]==0){ // repeat 0 No output
continue;
}else{ // General 0 Output zero , No bit name
printf("a");
}
}
}else{
printf("%c%c",a[i]+'a',b[i]);
}
}
}
return 0;
}summary :
There is an array of numbers , There is an array of digit names . Reverse output two arrays from large to small .
The other is the determination of reading rules .
Solution 2 :
#include <stdio.h>
#include <string.h>
int main()
{
int i,n;
char a[15];
scanf("%s",&a);
char b[9]={'\n','S','B','Q','W','S','B','Q','Y'};
if(a[0]=='0') {printf("a\n"); return 0;}
n=strlen(a);
for(i=0;i<n;i++){
if(a[i]=='0'){
if(i==n-4) printf("W");
if(i<n-1&&a[i+1]=='0'||i==n-1)continue; // The pronunciation of Chinese zero
else printf("a");
}else printf("%c%c",a[i]+'a'-'0',b[n-i-1]);
}
return 0;
}Input the number as a string ( Forward input )
边栏推荐
- Back to top implementation
- JS download files through URL links
- simpleParallax. JS (create poor visual effects for website pictures)
- Article content typesetting and code highlighting
- 交联环糊精金属有机骨架负载甲氨蝶呤缓释微粒|金属-有机多孔材料UiO-66负载黄酮苷类药物|齐岳
- JS shift operators (< <,> > and > > >)
- 28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
- 金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
- How to bold text in AI
- Too many files with unapproved license
猜你喜欢

Exercise 8-8 moving letters

Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs

Exercise 10-1 calculate the sum of 1 to n using recursive functions

Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them

Example analysis of QT learning 18 login dialog box

好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录

Leetcode(4)——寻找两个正序数组的中位数

FPGA test method takes mentor tool as an example

Mysql多表查询 #子查询

28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
随机推荐
FPGA test method takes mentor tool as an example
Exercise 10-1 judge the three digits that meet the conditions
QT learning 23 layout manager (II)
JVM object lifecycle
MongoDB数据库入门的常用命令
Similarities and differences between Allegro, OrCAD, net alias, port, off page connector and how to select them
Similarities and differences of sessionstorage, localstorage and cookies
Exercise 8-7 string sorting
小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
npm install卡住与node-npy的各种奇怪报错
Redis: operation command of string type data
[acnoi2022] guess numbers
牛客网:过河卒
[combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
jvm-类加载
Redis:字符串類型數據的操作命令
page owner特性浅析
LNMP环境mail函数不能发送邮件解决
x86汇编语言-从实模式到保护模式 笔记
simpleParallax. JS (create poor visual effects for website pictures)