HELLOWORLD


私信TA

用户名:HELLOWORD2016

访问量:3196

签 名:

等  级
排  名 2980
经  验 2001
参赛次数 1
文章发表 5
年  龄 0
在职情况 学生
学  校 河南农业大学
专  业

  自我简介:

解题思路:

首先需要明白读数存在映射关系,最简单的映射关系就是数组

其次,数字的位数不多应该可以不用数组转化字符串就可以解出来,我试了一下,放弃了,觉得还是将数字转化为字符串要好,因为我们计数一般是4位记录,读数的时候不就是加上那个,亿,万,就行


注意事项:

注意必须严格按照规范,比如说“10010”读作“yi  wan  ling  yi  shi”而不是“yi  wan  ling  shi”,“100000”读作“shi  wan”而不是“yi  shi  wan”,“2000”读作“er  qian”而不是“liang  qian”

格式很重要,我用了tap做标记,就是为了将2000 赌城 er qian

还有就是注意10010 之间的“0”要读出来 而1000 00000的“0”不需要读

具体的问题也是一点一点的解决的,我花了一个多小时!实践出真知,不要被代码吓住了,代码是根据思路走的,与做数学题一样!



参考代码:

#include<iostream>

#include<map>

#include<string>

#include<sstream>

int tap;

using namespace std;

string str[100];

string gcd(int n){

stringstream sstr;

sstr<<n;

string str=sstr.str();

return str;

}


void hello(int c){

  string s;

  s=gcd(c);

  int len=s.length();

  if(len>=4){ //第一步 

  cout<<str[s[0]]<<" "<<"qian"<<" ";

  if(s[1]=='0'&&(!(s[2]=='0'&&s[3]=='0'))) cout<<str[s[1]]<<" ";

  if(s[1]!='0')  cout<<str[s[1]]<<" "<<"bai"<<" ";

 

  if(s[2]=='0') {

  if(s[1]!='0'&&(!s[3]=='0'))

  cout<<str[s[2]]<<" ";

  } else  if(s[2]!=0) cout<<str[s[2]]<<" "<<"shi"<<" ";


if(s[3]!='0')

cout<<str[s[3]];

return;  //正确 

  }

  //

  else if(len>=3){

  cout<<str[s[0]]<<" "<<"bai"<<" ";

  if(s[1]=='0'&&(!(s[2]='0'))) cout<<str[s[1]]<<" ";

  if(s[1]!='0') cout<<str[s[1]]<<" "<<"shi"<<" ";

 

  if(s[2]!='0') 

    cout<<str[s[2]];

return;

  }

  //

   else if(len>=2){

   

    if(s[0]=='1'&&!tap) cout<<"shi"<<" ";

else cout<<str[s[0]]<<" "<<"shi"<<" ";

  if(s[1]!='0') cout<<str[s[1]];

return;

  }  

  //

  else if(len>=1){

  if(s[0]!='0')

  cout<<str[s[0]];

return;

  }  

  else return;

}


int main(){

    str['0']="ling";

str['1']="yi";

str['2']="er";

str['3']="san";

str['4']="si";

str['5']="wu";

str['6']="liu";

str['7']="qi";

str['8']="ba";

str['9']="jiu";

int n,a,b,c,d;

    while(cin>>n){

if(n==0) cout<<"ling"<<endl;

tap=0; //标记 

a=n/100000000;

if(a)  //!!!!

{

hello(a);

cout<<" "<<"yi"<<" ";

tap++;

}

b=n%100000000;

c=b/10000;

if(c) {  //!!!!

    if(c<1000&&a) cout<<"ling"<<" ";

hello(c);

cout<<" "<<"wan"<<" ";

tap++;

}

b=b%10000;

if(b) {

if(b<1000&&c) cout<<"ling"<<" ";

hello(b);

}

}

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区