L1-007 念数字 (10分)

输入一个整数,输出每个数字对应的拼音。当整数为负数时,先输出fu字。十个数字对应的拼音如下:

0: ling
1: yi
2: er
3: san
4: si
5: wu
6: liu
7: qi
8: ba
9: jiu
输入格式:
输入在一行中给出一个整数,如:1234。

提示:整数包括负数、零和正数。

输出格式:
在一行中输出这个整数对应的拼音,每个数字的拼音之间用空格分开,行末没有最后的空格。如 yi er san si。

输入样例:
-600
输出样例:
fu liu ling ling

#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include <iomanip>
#include<map>
#include<set>
#include<stack>
using namespace std;
int main()
{
    string a[10];
    a[0] = "ling";
    a[1] = "yi";
    a[2] = "er";
    a[3] = "san";
    a[4] = "si";
    a[5] = "wu";
    a[6] = "liu";
    a[7] = "qi";
    a[8] = "ba";
    a[9] = "jiu";
    int n;
    int m[20];
    cin >> n;
    if (n < 0)
    {
        cout << "fu ";
        n *= -1;
    }
    int num = n;
    int cnt = 0;
    if (n == 0)
        cout << a[0];
    while (num)
    {
        m[cnt] = num % 10;
        num /= 10;
        cnt++;
    }
    while (cnt)
    {
        cout << a[m[cnt - 1]];
        if (cnt != 1)
            cout << " ";
        cnt--;
    }
    cout << endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值