PAT Read Number in Chinese


Given an integer with no more than 9 digits, you are supposed to read itin the traditional Chinese way. Output "Fu" first if it isnegative. For example, -123456789 is read as "Fu yi Yi er Qian sanBai si Shi wu Wan liu Qian qi Bai ba Shi jiu". Note: zero("ling") must be handled correctly according to the Chinesetradition. For example, 100800 is "yi Shi Wan ling ba Bai".
输入描述:
Each input file contains one test case, which gives an integer with no more than 9 digits.


输出描述:
For each test case, print in a line the Chinese way of reading the number.  The characters are separated by a space and there must be no extra space at the end of the line.
示例1

输入

-123456789

输出

Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
// pat.cpp : 定义控制台应用程序的入口点。

//#include "stdafx.h"
#include"stdio.h"
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<deque>
#include<math.h>
using namespace std;
typedef long long ll;
string s;
string un[2]={"Wan","Yi"};
string unit[5]={"Qian","","Shi","Bai"};
string number[10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
int i=0;
int len;
string ans="";
bool iszero(int in){
	int last=in+4;
	for(;in<last;in++)
		if(s[in]!='0')return false;
	return true;


}


int main(){
	//freopen("c://jin.txt","r",stdin);
	cin>>s;
	len=s.length();
	if(s[0]=='-'){ans+="Fu ";i++;}
	int flag=0,f=0;;
	while(i<len){

		int j=len-i;
		int n=s[i]-'0';
		if(n!=0)
		{ans+=number[n];ans+=" ";
		if(j%4!=1)ans+=unit[j%4]+" ";
		flag=1;f=1;
		}
		else if(j%4!=1&&s[i+1]!='0'){
			ans+=number[n]+" ";
		}

		if(j==5){
			if(flag)ans+="Wan ";
			else{  while(i+1<len&&s[i+1]=='0')i++;
			if(i!=len-1)ans+="ling ";}
			flag=0;}
		else if(j==9){
			if(flag)
			{ans+="Yi ";}
			else{   while(i+1<len&&s[i+1]=='0')i++;
			if(i!=len-1)ans+="ling ";
			}
			flag=0;
		}
		if(j==1){

			if(f==0) ans+="ling";}
		i++;
	}

	while(ans[ans.length()-1]==' ')ans.erase(ans.end()-1);
	cout<<ans;

	//freopen("CON","r",stdin);
	//system("pause");

	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值