循环-19. 币值转换(20)
时间限制
400 ms
内存限制
32000 kB
代码长度限制
8000 B
判题程序
Standard
作者
陈建海(浙江大学)
输入一个整数(位数不超过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 <string>using namespace::std;int main(int argc, const char * argv[])
{long a;int i=0;string result="";char data[3]={0};// while (1) {result="";i=0;cin>>a;//cWdQbBaiwhile (a!=0) {string str="";int temp=a%10000;int tempG=temp%10;temp/=10;int tempS=temp%10;temp/=10;int tempB=temp%10;temp/=10;int tempQ=temp;if(tempQ!=0){data[0]='a'+tempQ;data[1]='Q';str.append(data);}else if(a>10000&&result[result.length()-1]!='a'){data[0]='a';data[1]=0;str.append(data);}if(tempB!=0){data[0]='a'+tempB;data[1]='B';str.append(data);}else if(tempQ!=0&&(tempS!=0||tempG!=0)){data[0]='a';data[1]=0;str.append(data);}if (tempS!=0){data[0]='a'+tempS;data[1]='S';str.append(data);}else if(tempQ!=0&&tempB!=0&&tempG!=0){data[0]='a';data[1]=0;str.append(data);}if (tempG!=0) {data[0]='a'+tempG;data[1]=0;str.append(data);}if (i==1&&a%10000!=0) {data[0]='W';data[1]=0;str.append(data);}else if(i==2){data[0]='Y';data[1]=0;str.append(data);}if(tempG==0&&a>10000&&result[0]!='a'&&result!=""){data[0]='a';data[1]=0;str.append(data);}a/=10000;result=str+result;i++;//iYbQdBcScWhQdBeSf}if(result==""){result="a";}cout<<result<<endl;//}return 0;
}