1082. Read Number in Chinese (25)
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output "Fu" first if it is negative. For example, -123456789 is read as "Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu". Note: zero ("ling") must be handled correctly according to the Chinese tradition. For example, 100800 is "yi Shi Wan ling ba Bai".
Input Specification:
Each input file contains one test case, which gives an integer with no more than 9 digits.
Output Specification:
For each test case, print in a line the Chinese way of reading the number. The characters are separated by a space and there must be no extra space at the end of the line.
Sample Input 1:-123456789Sample Output 1:
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiuSample Input 2:
100800Sample Output 2:
yi Shi Wan ling ba Bai
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int flagfirst = 1;
string s[10] = { "ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu" };
string quan[3] = { "Qian", "Bai", "Shi" };
int a[5];
int b[5];
void Exchange(int a[])
{
int flag1, flag2;
for (int i = 1; i < 5; i++)
{
flag1 = flag2 = 0;
if (a[i] != 0)
{
if (flagfirst)
{
flagfirst = 0;
cout << s[a[i]];
}
else
cout << " " << s[a[i]];
if (i!=4)
cout <<" "<< quan[i - 1];
}
else
{
for (int j = 0; j < i; j++)
{
if (a[j] != 0)
flag1 = 1;
}
for (int j = i + 1; j < 5; j++)
{
if (a[j] != 0)
flag2 = 1;
}
if (flag1==0 || flag2==0)
{
}
else
{
if (a[i - 1] != 0)
cout << " ling";
}
}
}
}
int main()
{
int n;
cin >> n;
if (n == 0)
{
cout << "ling";
return 0;
}
if (n < 0)
{
n = -n;
if (flagfirst)
{
cout << "Fu";
flagfirst = 0;
}
}
if (n / 100000000 != 0)
{
a[0] = 1;
if (flagfirst)
{
flagfirst = 0;
cout << s[n / 100000000] << " Yi";
}
else
cout << " " << s[n / 100000000] << " Yi";
}
a[1] = n % 100000000 / 10000000;
a[2] = n % 10000000 / 1000000;
a[3] = n % 1000000 / 100000;
a[4] = n % 100000 / 10000;
Exchange(a);
if (n / 10000 != 0)
{
b[0] = 1;
cout << " Wan";
}
b[1] = n % 10000 / 1000;
b[2] = n % 1000 / 100;
b[3] = n % 100 / 10;
b[4] = n % 10;
Exchange(b);
system("pause");
return 0;
}