币值转换

币值转换 (20 分)
输入一个整数(位数不超过9位)代表一个人民币值(单位为元),请转换成财务要求的大写中文格式。如23108元,转换后变成“贰万叁仟壹百零捌”元。为了简化输出,用小写英文字母a-j顺序代表大写数字0-9,用S、B、Q、W、Y分别代表拾、百、仟、万、亿。于是23108元应被转换输出为“cWdQbBai”元。
输入格式:
输入在一行中给出一个不超过9位的非负整数。
输出格式:
在一行中输出转换后的结果。注意“零”的用法必须符合中文习惯。
输入样例1:
​
813227345​
输出样例1:
​
iYbQdBcScWhQdBeSf​
输入样例2:
​
6900​
输出样例2:
​
gQjB​
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
void read(char* a);
void change(char* str,int x);
char num[11]="abcdefghij";
int main()
{

    char cap[10]="0SBQWSBQY";
    char num[11]="abcdefghij";

    unsigned int input;
    cin>>input;
    int x=input;
    int a=input%10000;
    input=input/10000;
    int b=input%10000;
    input=input/10000;
    int c=input%10000;

    char str1[5],str2[5],str3[5];

    change(str1,a);
    change(str2,b);
    change(str3,c);

    read(str3);
    if(c!=0)
        cout<<'Y';
    if(c!=0&&b<1000)
        cout<<'a';
    read(str2);
        if(b!=0)
            cout<<"W";
    if((b!=0||c!=0)&&a<1000)
        cout<<'a';
    read(str1);

    if(x==0)
        cout<<'a';  
    return 0;
}

void read(char* a)
{
    if(a[0]!='0')
        cout<<num[a[0]-'0']<<'Q';
    if(a[1]!='0')
        cout<<num[a[1]-'0']<<'B';
        else if(a[0]!='0'&&(a[2]!='0'||a[3]!='0'))
        cout<<'a';
    if(a[2]!='0')
        cout<<num[a[2]-'0']<<'S';
        else if(a[1]!='0'&&a[3]!='0')
            cout<<'a';
    if(a[3]!='0')
        cout<<num[a[3]-'0'];
}
void change(char* str,int x)
{
    str[3]=x%10+'0';
        x=x/10;
    str[2]=x%10+'0';
        x=x/10;
    str[1]=x%10+'0';
        x=x/10;
    str[0]=x%10+'0';
、

 

posted @ 2019-03-01 17:51  时光碎片  阅读(121)  评论(1编辑  收藏  举报