1417: [蓝桥杯]数的读法 【未完成】

在这里插入图片描述
http://oj.ecustacm.cn/problem.php?id=1417

这道题处理好恶心,过了70% 细节太多了,懒得搞了有时间在看看吧。

#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
map<int,string> mp;
/*
亿 
万
千
百
十 
*/
void f(int x,bool st)
{
	bool flag1=false,flag2=false,flag3=false; 
	if(x>=1000) cout<<mp[x/1000]<<" "<<"qian ",flag1=true;
	x=x%1000;
	if(x>=100)  cout<<mp[x/100]<<" "<<"bai ",flag2=true;
	x=x%100;
	if(x>=10) {
			if( (flag1&&!flag2) ||st) cout<<"ling ";
			if(st||flag1||flag2||x/10!=1)cout<<mp[x/10]<<" "<<"shi ";
			else cout<<"shi ";
			flag3=true;
	}
	x=x%10;
	if((!flag3)&&(flag1||flag2)&&x) cout<<"ling ";
	if(x) cout<<mp[x]<<" ";
}
int main(void)
{
	mp[0]="ling",mp[1]="yi",mp[2]="er",mp[3]="san",mp[4]="si",mp[5]="wu";
	mp[6]="liu",mp[7]="qi",mp[8]="ba",mp[9]="jiu",mp[10]="shi";
	
	long long int x; cin>>x;
	bool flag1=false,flag2=false,flag3=false;
	if(x>=1e8) 
	{
		
		f(x/(100000000),flag1);
		cout<<"yi ";
		flag1=true;
	}
	x=x%(100000000);
	if(x>=1e4)
	{
		f(x/(10000),flag2);
		cout<<"wan ";
		flag2=true;
	}
	x=x%(10000);
	if(flag1||flag2) flag3=true;
	if(x)
	{
		f(x,flag3);
	}
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值