1082 Read Number in Chinese(25 分)

#include
#include
using namespace std;
char num[10][10] = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu" };
char wei[5][10] = { "Shi","Bai","Qian","Wan","Yi" };

int main()
{
    string s;
    getline(cin, s);
    int left = 0, right = s.length() - 1;
    if (s[0] == '-')
    {
        printf("Fu");
        left++;
    }
    while (left + 4 <= right)
    {
        right -= 4;
    }
    while (left < s.length())
    {
        bool flag = false, isPrint = false;
        while (left <= right)
        {
            if (left > 0 && s[left] == '0')
            {
                flag = true;
            }
            else
            {
                if (flag == true)
                {
                    printf(" ling");
                    flag = false;
                }
                if (left > 0)printf(" ");
                printf("%s", num[s[left] - '0']);
                isPrint = true;
                if (left != right)
                {
                    printf(" %s", wei[right - left - 1]);
                }
            }
            left++;
        }
        if (isPrint&&right != s.length() - 1)printf(" %s", wei[(s.length() - 1 - right) / 4 + 2]);
        right += 4;
    }
    return 0;
}

你可能感兴趣的:(1082 Read Number in Chinese(25 分))