当前位置:网站首页>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:
gQjB
Solution 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 )
边栏推荐
- Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride( Exercise 10-8 recursive implementation of sequential output of integers
- Too many files with unapproved license
- “又土又穷”的草根高校,凭什么被称为“东北小清华”?
- Redis: commandes d'action pour les données de type chaîne
- 7-10 calculate salary
- Leetcode(4)——尋找兩個正序數組的中比特數
- Uio-66-cooh loaded bendamostine | hydroxyapatite (HA) coated MIL-53 (FE) nanoparticles | baicalin loaded manganese based metal organic skeleton material
- Exercise 6-2 using functions to sum special A-string sequences
- Fabric. JS document
猜你喜欢
JS matrix zero
[email "/>
Doxorubicin loaded on metal organic framework MIL-88 DOX | folic acid modified uio-66-nh2 doxorubicin loaded [email
Scroll detection of the navigation bar enables the navigation bar to slide and fix with no content
八大排序
concat和concat_ws()区别及group_concat()和repeat()函数的使用
好看、好用、强大的手写笔记软件综合评测:Notability、GoodNotes、MarginNote、随手写、Notes Writers、CollaNote、CollaNote、Prodrafts、Noteshelf、FlowUs、OneNote、苹果备忘录
Polestar美股上市:5.5万台交付如何支持得起超200亿美元估值
玖逸云黑免费无加密版本源码
常见问题之PHP——ldap_add(): Add: Undefined attribute type in
JVM class loading
随机推荐
MongoDB数据库入门的常用命令
Leetcode (4) -- find the median of two positively ordered arrays
Jiuyi cloud black free encryption free version source code
7-8 overspeed judgment
金属有机骨架材料ZIF-8包载姜黄素([email protected]纳米颗粒)|纳米金属有机框架搭载雷帕霉素|科研试剂
常见问题之PHP——ldap_add(): Add: Undefined attribute type in
剑指 Offer 28. 对称的二叉树
Raft 协议
Current situation, analysis and prediction of information and innovation industry
28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
Thinking about the arrangement problem in the backtracking problem (leetcode questions 46 and 47)
Analysis of the characteristics of page owner
愉悦资本新双币基金近40亿元完成首次关账
Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs
金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
Why don't I have a rookie medal
FPGA测试方法以Mentor工具为例
编程语言:类型系统的本质
Similarities and differences of sessionstorage, localstorage and cookies
Exercise 6-6 use a function to output an integer in reverse order