zoukankan      html  css  js  c++  java
  • 1082 Read Number in Chinese (25分)

    注意事项:

    八千万八千(√),八千万零八千(×)

    输入为0时单独判断

    #include <iostream>
    #include <cstring>
    using namespace std;
    int main()
    {
        char out_num[10][5] = { "yi","er","san","si","wu","liu","qi","ba","jiu" };
        char out[3][7] = { " Shi"," Bai"," Qian" };
        char N[11];
        bool first = true;
        bool print_zero = true;//Wan与Qian
        cin >> N;
        if (N[0] == '-')
        {
            cout << "Fu";
            first = false;
            for (int i = 0; i < strlen(N); ++i)
            {
                N[i] = N[i + 1];
            }
        }
        int len = strlen(N);
        int zero = 0;//是否积累“零”
        int dif;
        for (int i = 0; i < len; ++i)
        {
            dif = len - i;
            if (dif < 5)
            {
                if (N[i] != '0')
                {
                    if (zero == 1)
                    {
                        cout << " ling";
                        zero = 0;
                    }
                    if (!first)cout << " ";
                    first = false;
                    cout << out_num[N[i] - '0' - 1];
                    if (dif >= 2)
                        cout << out[dif - 2];
                }
                else
                {
                    if (i == 0)
                    {
                        cout << "ling";
                        return 0;
                    }
                    zero = 1;
                }
            }
            else if (dif == 5)
            {
    
                if (N[i] != '0')
                {
                    if (zero == 1)
                    {
                        cout << " ling";
                        zero = 0;
                    }
                    if (!first)cout << " ";
                    first = false;
                    cout << out_num[N[i] - '0' - 1];
                }
                if (!(N[len - 6] == '0' && N[len - 7] == '0' && N[len - 8] == '0'))
                {
                    cout << " Wan";
                    zero = 0;
                }
    
            }
            else if (dif > 5 && dif < 9)
            {
                if (N[i] != '0')
                {
                    zero = 0;
                    if (!first)cout << " ";
                    first = false;
                    cout << out_num[N[i] - '0' - 1];
                    if ((dif + 2) % 4 >= 0)
                        cout << out[(dif + 2) % 4];
                }
                else
                {
                    zero = 1;
                }
            }
            else if (dif == 9)
            {
                if (!first)cout << " ";
                first = false;
                cout << out_num[N[i] - '0' - 1] << " Yi";
            }
        }
        return 0;
    }
  • 相关阅读:
    java 上传图片
    getElementById 鼠标经过字体改变颜色
    getElementById 学习
    css的绝对定位与相对定位
    关于For循环
    扩展方法的应用
    关于Function 的学习笔记
    <a>标签中查找文件的方法
    关于Name ID class属性的区别
    使用float设置经典的网站前端结构
  • 原文地址:https://www.cnblogs.com/2020R/p/13752264.html
Copyright © 2011-2022 走看看