数字转中文表示
来源:互联网 发布:怎样发淘宝链接网址 编辑:程序博客网 时间:2024/05/04 02:12
此处表达式不超过万。
注意的地方:1000,可以1001,即0的情况 (首,中,尾),11 ,12等,10 20 等情况!
此处未考虑负数情况,可以加以判断,并且在开始加入负
#include <iostream>#include <string>#include <vector>using namespace std;string int_to_num(int num);int main(){int num;cin>>num;cout<<int_to_num(num)<<endl;return 0;}string int_to_num(int num){string num_str[] = {"零","一","二","三","四","五","六","七","八","九"};string base_str[] = {"","十","百","千","万" };string res;int count = 0;if(num == 0) return num_str[0];int num_low[10];while(num != 0){int num_digit = num%10;num = num/10;num_low[count] = num_digit;if(num_digit == 0 && count == 4 )//字母头为0{if(num_low[count-1] == 0)//高位连续为0知道万位!!{res = res.substr(num_str[0].size(),res.size()-num_str[0].size());}break;}if(num_digit == 0&&count >= 1 && num_low[count-1] != 0 )//防止1000,可以1001,即0的情况{res = num_str[num_digit]+res;}else if(num_digit == 1&&count == 1&&num == 0)//防止11,12等情况{res = base_str[num_digit]+res;}else{if(num_digit > 0)//必须大于0{res = num_str[num_digit]+base_str[count]+res;}}count++;if(count >= 5)break;}return res;}如果代码有bug,希望各位指正,谢谢。
0 0
- 数字转中文表示
- 把数字转换成中文货币表示
- 把数字转换成中文货币表示
- 将中文数字转换成英文表示
- 把中文表示的数字转成阿拉伯数字
- 涉及到数字中文表示的一些工具函数
- 阿拉伯数字表示的数字转换成中文习惯读法
- 表示数字
- 表示数字
- 表示数字
- 表示数字
- 表示数字
- 表示数字
- 数字转中文数字大写
- java 转中文数字
- Java 数字转中文
- 数字转中文
- 数字转中文
- 字符数组的初始化和赋值
- MIPI video mode 和 command mode 的区别
- Android中<meta-data>的使用
- UVA 10413 - Crazy Savages(数论)
- 安佑集团应用FineReport建云端平台报表系统
- 数字转中文表示
- LinkedList中将对象按照某一属性排序
- MySQL C/C++ API 问题汇总
- qt string qstring 解析
- 随记
- php utf-8编码 正则匹配中文
- 远程连接pgsql数据库常用命令
- 消息中间件的技术选型心得-RabbitMQ、ActiveMQ和ZeroMQ
- ubuntu配置php时出现:Cannot load libexec/libphp5.so into server