华为oj 人民币转换
2016-03-09 17:33
363 查看
测试发现我的程序还有bug,不过可以通过oj。。。
#include<iostream> #include<string> using namespace std; int main() { string tran1[10] = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }; string tran2[5] = { "拾", "佰", "仟", "万", "亿" }; string in, tin = "", result = "元"; int jiao = 0, fen = 0; cin >> in; int count = 0; bool flag = false; for (int i = 0; i < in.size(); i++) { if (in[i] != '.'&&!flag) { tin += in[i]; } else { flag = true; if (count == 1) { jiao = in[i] - '0'; } else if (count == 2) { fen = in[i] - '0'; } count++; } } if (tin[tin.size() - 1] != '0') { result = tran1[tin[tin.size() - 1] - '0'] + result; } int count1 = 0; for (int i = tin.size() - 2; i >= 0; i--) { if (tin[i] - '0' != 0) { if (count1 == 8) { result = tran2[4] + result; } else { result = tran2[count1 % 4] + result; } if (tin[i] - '0' != 1 || count1 % 4 != 0) { result = tran1[tin[i] - '0'] + result; } } count1++; count1 %= 9; } //输出 cout << "人民币" << result; if (!jiao&&!fen) { cout << "整" << endl; } else { if (jiao) { cout << tran1[jiao] << "角"; } if (fen) { cout << tran1[fen] << "分"; } cout << endl; } return 0; }结论:这道题很复杂,很复杂,很复杂!!!
相关文章推荐
- 各大学习网址总结
- next_permutation函数
- Process 'command '...\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 2
- GDOI模拟 染色配对
- Apache HttpClient 4.3开发指南 实现URL重定向
- Sublime Text 3 配置浏览器预览路径 localhost
- Python多线程学习
- JavaEE_Junit_Junit对Spring注入的Service层的测试
- Sicily 1488 矩阵取数游戏
- CodeForces 630J:Divisibility 【数学】
- FPGA 竞争与冒险
- Lua中的面向对象编程
- Github——创建GitHub技术博客全攻略
- Broadcast receiver 的使用
- 全排列一个数组
- 二维码加logo demo
- WebApi说明文档插件
- vb6 winhttp 上传文件
- Activity的顶层窗体
- iosUI篇-Date Picker 和 UITool Bar 控件简单的介绍