PAT-1082. Read Number in Chinese (25)(模拟)
2016-03-03 21:11
239 查看
4位4位的考虑,情况比较多,且要把中间结果存起来,最后输出,因为空格的原因。
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> using namespace std; char words[12][10] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu", "shi"}; char output[30][10]; int cnt = 0; void read(int n) { int a, b, c, d; a = n/1000; b = (n-1000*a)/100; c = (n-1000*a-100*b)/10; d = n-1000*a-100*b-10*c; if (a != 0) { strcpy(output[cnt++], words[a]); strcpy(output[cnt++], "Qian"); } if ((b == 0) && a != 0 &&(c != 0 || d != 0)) strcpy(output[cnt++], "ling"); else if (b != 0) { strcpy(output[cnt++], words[b]); strcpy(output[cnt++], "Bai"); } if (c == 0 && b!= 0 && d != 0) strcpy(output[cnt++], "ling"); else if (c != 0) { strcpy(output[cnt++], words[c]); strcpy(output[cnt++], "Shi"); } if (d != 0) strcpy(output[cnt++], words[d]); } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int N = 0; cin >> N; if (N==0) { cout << "ling"; return 0; } if (N < 0) { strcpy(output[cnt++], "Fu"); N = -N; } int yi, wan, ge; yi = N/100000000; wan = (N-100000000*yi)/10000; ge = N-100000000*yi - 10000*wan; if (yi != 0) { read(yi); strcpy(output[cnt++], "Yi"); } if (wan != 0) { if (yi != 0 && wan < 1000) strcpy(output[cnt++], "ling"); read(wan); strcpy(output[cnt++], "Wan"); } if (ge != 0) { if ((wan != 0 && ge < 1000) || (wan == 0 && yi != 0 && ge < 1000)) strcpy(output[cnt++], "ling"); read(ge); } for (int i = 0; i < cnt; i++) { cout << output[i]; if (i != cnt-1) cout << " "; } return 0; }
相关文章推荐
- Web开发学习之路--Eclipse+Tomcat+mysql之初体验
- C辗转相除法求最大公约数的实现
- BootStrap详解之(一)
- DSP 2812: 使用C++封装中断控制器PIE
- Android Studio 1.3及以上 NDK环境配置
- hdu 1272 小希的迷宫 解题报告
- PAT-A1077. Kuchiguse (20)(模拟)
- 第一次写博客
- SQL Server 2008 R2 完全卸载与重新安装
- xib自定义UIView报错误 "forUndefinedKey:]: this class is not key value coding-compliant for the key"
- hiho Hamiltonian Cycle
- Android Fragment 基础初识(下)
- C指针作为函数参数引用
- Navicat for MySQL用ssh功能连接远程数据库
- cocos2dx 基础
- Android学习之接口Interface
- Codeforences #309 C(div2)
- base.superclass.constructor.call(this,config)
- 在虚拟主机下的实用curl 本地127.0.0.1 以及301问题
- AngularJS中的依赖注入