当前位置:网站首页>PTA basic question 7-23 currency conversion (20 points) (true)
PTA basic question 7-23 currency conversion (20 points) (true)
2022-07-22 18:54:00 【Now there is no forgotten thought】
7-23 Currency conversion (20 branch )
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
No blank lines at the end
sample output 1:
iYbQdBcScWhQdBeSf
No blank lines at the end
sample input 2:
6900
sample output 2:
gQjB
analysis : This question is true. It's disgusting , Many special situations and details , I haven't thought of a good method for the time being , Poke an eye , Update later if you have ideas . The current idea is : Start with the most general situation , for example 123456789, Then consider the middle and end bands 0 The situation of ; The code is as follows :
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[10],cnt=0;
do {
a[cnt++]=n%10;
n/=10;
} while (n);
char b[15]="abcdefghij";
int t=0;
for (int i=cnt-1;i>=t;i--) {
if (i==4&&a[i]==0) {
printf("W");
continue;
} else printf("%c",b[a[i]]); // Wan weishang is 0 No output 0, Ten thousand still need to be output , example 6902312;
// 6900; Handle the ending band 0( Do not output all ending bands 0 Part of , When 10000 bits are included, 10000 still need to be output )
if (a[0]==0) {
int j=1;
while (a[j]==0) {
j++;
}
if (j>=1) t=j;
}
// 100000001; 69002 Deal with the median 0, Push it down ( Multiple zeros are output only once )
if (a[i]==0) {
int j=i;
while (a[j]==0) {
j--;
}
i=j+1;
}
if (i==4) printf("W");
if (a[i]) {
if (i==8) printf("Y");
if (i==7||i==3) printf("Q");
if (i==6||i==2) printf("B");
if (i==5||i==1) printf("S");
}
}
}
Debugging slowly can only be said to be , There are also various ways to solve this problem , Poke an eye , Let's see later .
边栏推荐
- IP, subnet mask, gateway, IPS and IDS
- Flink学习笔记(四)Flink运行时架构
- Exercise 7-4 find out the elements that are not common to two arrays (C language)
- Over the weekend, I had a dinner with the technology gurus and talked about the "golden nine and silver ten" peak of the software testing industry [the trend of involution has been formed]
- ECSHOP need to modify the folder and file of permission? The error directory cannot be written
- Qt | boîtes de dialogue modales et non modales qdialog
- LeetCode 693. 交替位二进制数
- 1.QTableWidget插入按钮,灵活删除本行,一列显示行号
- NRF24L01无线模块设置发射接受模式方法
- Summary 20220209
猜你喜欢
04. interface aggregation principle
There is no session in the tensorflow module
MySQL的语句执行顺序
连接mysql8.0出现caching-sha2-password问题
sql 语法中 join 的所有用法总结(简单例子)
Caching-sha2-password problem occurred when connecting mysql8.0
1.Qt之打包发布程序 (NSIS);
如何解决执行yum makecache命令过程中出现的错误
TCP and UDP, three handshakes and four waves
ps: 如何调出辅助线
随机推荐
项目启动过后,一直循环加载mapper xml文件
LeetCode 2028. 找出缺失的观测数据
练习7-4 找出不是两个数组共有的元素(C语言)
ECSHOP need to modify the folder and file of permission? The error directory cannot be written
Qt | 模態對話框和非模態對話框 QDialog
Summary 20220214
1.qt 查看源码
Summary 20220210
1.创建函数的动态库,2.HOWTO Create and Deploy a Sample DLL using MinGW
No input file specified solution
PTA search tree judgment
Vlfeat, pydot configuration
位与:一个数&1的结果
IP address, CIRD format URL, hostname regular expression
webFlux 中使用 openFeign 实现远程调用遇到的问题
The database is garbled. Do you want to find a solution?
Summary of various technical data -mysql
How can ECSHOP run super slow locally?
Uniapp wechat applet map, open in Gaode app, Tencent app, baidu app, apple map app
Leetcode 116. fill in the next right node pointer of each node