wu


私信TA

用户名:cncfvc

访问量:215380

签 名:

读研狗没有时间刷题了~~

等  级
排  名 2
经  验 36025
参赛次数 8
文章发表 265
年  龄 25
在职情况 学生
学  校 电子科技大学
专  业 通信工程

  自我简介:

写代码 真好玩 ~

小弟不才 花了一个下午 写了将近120行代码  才AC

这题写起来 比较恶心  也比较复杂 所以好像没什么人去做

但我耐着性子AC了,所以希望大家能有恒心  有毅力  不要害怕出错

每一次出错就会是一点进步  至于题目的解法  没什么好说的


   亿       万 千 百 十 
1  1 2 3 4  5  6  7  8   9
考虑一些特殊情况 
1、110000 读作  十一万  而不是一十一万 
2、1010  读作一千零一十  而不是一千零十
3、我们要考虑在特殊位上的数字  比如说 十万位 当十万位前面没有数的时候 它读十  而不是 一十
4、考虑0的读法 如果0 在万位、个位、以及亿位的时候都不需要读
5、如果有两个连续的0则只读前面一个 1001 读左一千零一 而不是一千零零一
6、11读作十一 而不是一十一,所以考虑十位上的数字,并且它前面没有数字的时候读十一
7、万位上的数字如果它前面的十万,百万,千万位都是0,那么“万”字就不用输出
8、答案都在代码里。
9、写的不好 求轻喷



#include<iostream>
#include<cstring>
using namespace std;
char a[20][10]={{"ling"},{"yi"},{"er"},{"san"},{"si"},{"wu"},{"liu"},{"qi"},{"ba"},{"jiu"}};
char b[20][10]={{" "},{"shi"},{"bai"},{"qian"},{"wan"},{" "},{" "},{" "},{"yi"},{" "},{" "}};
void f(string str)
{
	string str1;
	int j=0;
	for(int i=str.length()-1;i>=0;i--)
	{
		str1[j++]=str[i];
	}
	str1[j]='*';
	for(int i=j-1;i>=0;i--)
	{
		if(i>=1)
		{
		  if(i>=8&&i<=9)
		  {
			
			if(i==9)
		    {
				if(str1[i]-'0'==1)
				cout<<b[10-i]<<" ";
				else
				{
					cout<<a[str1[i]-'0']<<" ";
					cout<<b[10-i]<<" ";
				}
			}
			else
			{
			if(str1[i]-'0'!=0)
			cout<<a[str1[i]-'0']<<" ";
			if(b[i]!=" "&&str1[i]-'0'!=0)
			cout<<b[i]<<" ";
			else
				cout<<b[8]<<" ";
	    	}
	      }
	      else if(i>4&&i<=7)
	      {
	      	if(i==5)
	      	{
	      		if(str1[i]-'0'==1&&str1[i+1]=='*')
				  cout<<b[1]<<" ";
				else
				{
					if(str1[i]-'0'!=0||str1[i]-'0'==0&&str1[i-1]-'0'!=0)
					cout<<a[str1[i]-'0']<<" ";
					if(str1[i]-'0'!=0)
					cout<<b[1]<<" "; 
				}
				  
			}
	        else
	        {
	        if(str1[i]-'0'!=0||str1[i]-'0'==0&&str1[i-1]-'0'!=0)
	      	cout<<a[str1[i]-'0']<<" ";
	      	if(b[i-4]!=" "&&str1[i]-'0'!=0)
	      	cout<<b[i-4]<<" ";	
			}
		  }
		  else if(i==4)
		  {
		  	if(str1[i]-'0'!=0)
		  	cout<<a[str1[i]-'0']<<" ";
		  	if(str1[i]-'0'==0&&str1[i+1]-'0'==0&&str1[i+2]-'0'==0&&str1[i+3]-'0'==0)
		  	cout<<"";
		  	else
			cout<<b[4]<<" "; 
		  }
		  else
		  {
		    if(i==1)
	      	  {
	      		if(str1[i]-'0'==1&&str1[i+1]=='*')
				  cout<<b[1]<<" ";
				else
				{
					if(str1[i]-'0'!=0||str1[i]-'0'==0&&str1[i-1]-'0'!=0)
					cout<<a[str1[i]-'0']<<" ";
					if(str1[i]-'0'!=0)
					cout<<b[1]<<" "; 
				}
				  
			}
			else
			{
		    if(str1[i]-'0'!=0||str1[i]-'0'==0&&str1[i-1]-'0'!=0)
		  	cout<<a[str1[i]-'0']<<" ";
		  	if(b[i]!=" "&&str1[i]-'0'!=0)
		  	cout<<b[i]<<" ";
		    }
		  }
		}
		else
		{
			if(str1[i]-'0'!=0)
			cout<<a[str1[i]-'0'];
		}
	}
	cout<<endl;
}
int main()
{
		string str;
		while(cin>>str)
		{
			f(str);
		}
		return 0;
	
}


 

0.0分

0 人评分

  评论区