有符号整数(int)的汉语读法。

发布时间:2020-07-21 12:42:51 作者:碍人i
来源:网络 阅读:940

        


请实现一个函数,给定一个32为有符号整数(int 类型),函数输出该数字符合汉语习惯的读法。例如:10086 读作 " 一万零八十六"。

#include<iostream>
#include<list>
#include<string>
#include<stdlib.h>
#include<math.h>
using namespace std;
void m_itoa(int num,list<char> &vt)
{
    int n=num; 
    if(num<0)
        n=abs(num);
    while(n>0)
    {
        vt.push_front(n%10+'0');
        n/=10;
    }
}
int main()
{
    string n1[]={"零","一","二","三","四","五","六","七","八","九"};
    string n2[]={"个","十","百","千","万","十","百","千","亿","十"};
    int num;
    cin>>num;
    if(num<0)
        cout<<"负";
    list<char> vt;
    m_itoa(num,vt);
    list<char>::iterator str;
    int i=vt.size();
    for(str=vt.begin();str!=vt.end();--i,++str)
    {
        if(*str=='0')
        {
            if(i>8)
                cout<<n2[8];
            else if(i<8 && i>4)
                cout<<n2[4];
                        while(*str=='0')
                        {
                                str++;i--; 
                        }
            if(str==vt.end())
                break;
            else        
                cout<<n1[0];
        }
        cout<<n1[*str-'0'];
        if(i>1)
                cout<<n2[i-1];
    }
    cout<<endl;
    return 0;
}


推荐阅读:
  1. apache的读法是什么
  2. Python3怎么实现汉语转换为汉语拼音

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

符号 整数 汉语读法

上一篇:Centos5.6下安装Nagios PNP

下一篇:完全备份数据和差异备份数据的shell脚本

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》