PAT-A-1082. Read Number in Chinese (25)
来源:互联网 发布:淘宝上雪莲蛹虫草膏 编辑:程序博客网 时间:2024/05/07 02:05
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;
}
- PAT A.1082. Read Number in Chinese
- PAT A 1082. Read Number in Chinese (25)
- PAT-A-1082. Read Number in Chinese (25)
- PAT A.1082. Read Number in Chinese (25)
- PAT A 1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese (25)
- pat 1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese(25)
- PAT 1082. Read Number in Chinese (25)
- 【PAT】1082. Read Number in Chinese (25)
- PAT:1082. Read Number in Chinese (25)
- 1082. Read Number in Chinese (25) PAT
- PAT 1082. Read Number in Chinese (25)
- PAT 1082. Read Number in Chinese
- 【PAT】1082. Read Number in Chinese
- 【PAT】A1082. Read Number in Chinese (25)
- PAT(Advance) 1082. Read Number in Chinese (25)
- 自定义dialog
- Recurrent Recommender Networks
- 阿里云 linux apache+mysql+php
- 使用真机做测试机遇到的坑
- 正则表达式功能2
- PAT-A-1082. Read Number in Chinese (25)
- 类什么时候被加载
- JSP字符编码过滤器 防止乱码
- 正则表达式练习
- 第八周:(LeetCode 516) Longest Palindromic Subsequence(c++)
- 并查集与路径压缩
- 正则表达式(网页爬虫)
- 【考试总结】[CQOI2017]考试总结
- python 基础教程 23章NNTP 1