1082. Read Number in Chinese (25)
2015-12-19 12:02
453 查看
#include<cstdio> #include<cstring> #include<iostream> #include<cstdlib> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> using namespace std; int main() { const char *str[9]={"","Shi","Bai","Qian","Wan","Shi","Bai","Qian","Yi"}; const char *num[10]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; char s[10]; vector<const char*> v; scanf("%s",s); int length=strlen(s); if(s[0]=='-') { v.push_back("Fu"); for(int i=0;i<length;i++) s[i]=s[i+1]; length--; } else if(s[0]=='0'&&length==1) { printf("ling\n"); return 0; } int flag=0; int cnt=0; for(int i=0;i<length;i++) { if(s[i]!='0') { if(cnt>0&&(length-i-1!=4||s[i]!=0 )) v.push_back("ling"); v.push_back(num[s[i]-'0']); cnt=0; } else if(s[i]=='0') { cnt++; } if(cnt>0&&length-i-1==4&&cnt<4&&s[i]=='0') v.push_back(str[length-i-1]); else if(i!=length-1) { if(s[i]!='0') v.push_back(str[length-i-1]); } } for(int i=0;i<v.size();i++) if(i==0) printf("%s",v[i]); else printf(" %s",v[i]); printf("\n"); return 0; }
相关文章推荐
- QQ空间快速登录地址
- 从框架看PHP的五种境界及各自的薪资待遇
- 二叉搜索树的搜索和最值情况
- tc-SRM-626-DIV1-250
- Hive的日期函数
- 自己动手写CPU之第九阶段(8)——MIPS32中的LL、SC指令说明
- shell 入门
- C#中使用DotNetZip选择指定文件并解压
- START WITH CONNECT BY PRIOR子句实现递归查询
- Received CISSP Lapel PIN
- Auto Layout(Storyboard)
- 带有EXISTS谓词的子查询
- MySQL的timeout超时你遇到过几种情况
- 开源日志系统比较:scribe,chukwa,kafka,flume
- 使用 Node.js、Express、AngularJS 和 MongoDB 构建一个Web程序
- Python 基础【第八篇】变量
- 在PHP中使用协程实现多任务调度
- CP学习笔记(9) - 迭代
- UFLDL教程答案(4):Exercise:Softmax Regression
- hdu 4472 Count (递推)