清澄A1052-数的读法

【问题描述】

给定一个阿拉伯数字串,你帮他按照中文读写的规范转为汉语拼音字串,相邻的两个音节用一个空格符格开。

【解决过程】

931580
CPP
正确
100
83
0ms
864.0KB
927B
我的思路:四位一读(可能还有没查出来的bug,但过了测试数据)

代码如下:

#include<iostream>
#include<string>
using namespace std;
string ans,temp,
       zh_num[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"},
       zh_unit[]={"shi","bai","qian","wan","yi"};
int first=1;
void add(string s){
	if(first) first=0;
	else temp+=' ';
	temp+=s;
}
int main(){
	int n;
	cin>>n;
	int digit,k=0;
	while(n){
		digit=n%10000;
		n/=10000;
		first=n?0:1;
		int a=digit/1000,b=digit/100%10,c=digit%100/10,d=digit%10;
		//cout<<a<<b<<c<<d;
		if(a){
			add(zh_num[a]);
			add(zh_unit[2]);
		}
		if(n&&digit&&(!a||a+b==0||a+b+c==0)) add(zh_num[0]);
		if(b){
			add(zh_num[b]);
			add(zh_unit[1]);
		}
		if(a&&!b&&d) add(zh_num[0]);
		if(c){
			if(c==1){
				if(n||(a||b)) add(zh_num[c]);
			}else add(zh_num[c]);
			add(zh_unit[0]);
		}
		if(b&&!c&&d) add(zh_num[0]);
		if(d){
			add(zh_num[d]);
		}
		if(k&&digit) add(zh_unit[2+k]);
		++k;
		ans=temp+ans;
		temp.clear();
	}
	cout<<ans<<endl;
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值