小弟不才 花了一个下午 写了将近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 人评分
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)浏览:510 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:661 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:606 |
企业奖金发放 (C语言代码)浏览:2319 |
上车人数 (C语言代码)浏览:711 |
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:713 |
【魔板】 (C++代码)浏览:1158 |
1025题 初学者,求帮忙看下,不知道哪错了浏览:316 |
蓝桥杯基础练习VIP-报时助手 (C++代码)浏览:1064 |
C二级辅导-统计字符 (C语言描述——用函数求解)浏览:1181 |