1082. Read Number in Chinese (25)

时间限制  
400 ms
内存限制  
32000 kB
代码长度限制  
16000 B
判题程序    
Standard    
作者    
CHEN, Yue

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:
-123456789
Sample Output 1:
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
Sample Input 2:
100800
Sample Output 2:
yi Shi Wan ling ba Bai
 
简单的模拟。仅仅是过程描写叙述有点啰嗦。
首先这句话什么意思  Note: zero ("ling") must be handled correctly according to the Chinese tradition
什么叫Chinese tradition,事实上就是对0的特殊处理。
【1】尾部的0不发音
【2】多个连续的0,仅仅发一个音
【3】多个不连续的0。都要发音
【4】大于4位的数肯定要发 Wan 音
【5】大于8位的数一定要发 Yi 音
并且还有个规律: Shi Bai Qian 这三个音循环出现。

 
Ac代码:
 
// pat-1082.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h" #include "iostream"
#include "string"
#include "algorithm"
#include "vector"
#include "stack" using namespace std;
stack<string> ans;
string num[]={"ling", "yi" ,"er" , "san" , "si" , "wu", "liu" , "qi", "ba", "jiu"};
string pos[]={ "Shi","Bai","Qian", "Wan","Yi" };
int main()
{
long int n=0;
bool firstout=true;
cin>>n;
if (n==0)
{
cout<<"ling";
goto end;
}
if (n<0)
{
cout<<"Fu";
firstout=false;
n=-(n);
}
int cnt=0;
bool wan_flag=false;
bool zero=false;
bool first=true;
while(n)
{
int temp=n%10;
//0 特殊处理
if (temp==0)
{
if (cnt==3)
{
wan_flag=true;
}
n/=10;
if (!first)
{
cnt++;
}
first=false;
if (zero)//第一次遇到0
{
ans.push(num[0]);
zero=false;
continue;
}
else
{
continue;
}
}
zero=true;
if(first)//忽略个位
{
ans.push(num[temp]);//yi er san si ~~~~~
n/=10;
first=false;
continue;
}
if(cnt<7)
{
if (wan_flag)
{
wan_flag=false;
ans.push(pos[3]);
}
ans.push(pos[cnt%4]);//shi bai qian wan
}
else
{
ans.push(pos[4]);//yi
} ans.push(num[temp]);//yi er san si ~~~~~ n/=10;
cnt++; }
while (!ans.empty())
{
string temp=ans.top();
ans.pop();
if (firstout)
{
firstout=false;
cout<<temp;
continue;
}
cout<<" "<<temp;
}
end: return 0;
}

 
 

pat解题报告【1082】的更多相关文章

  1. PAT 解题报告 1052. Linked List Sorting (25)

    1052. Linked List Sorting (25) A linked list consists of a series of structures, which are not neces ...

  2. PAT 解题报告 1051. Pop Sequence (25)

    1051. Pop Sequence (25) Given a stack which can keep M numbers at most. Push N numbers in the order ...

  3. PAT 解题报告 1050. String Subtraction (20)

    1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...

  4. PAT 解题报告 1049. Counting Ones (30)

    1049. Counting Ones (30) The task is simple: given any positive integer N, you are supposed to count ...

  5. PAT 解题报告 1048. Find Coins (25)

    1048. Find Coins (25) Eva loves to collect coins from all over the universe, including some other pl ...

  6. PAT 解题报告 1047. Student List for Course (25)

    1047. Student List for Course (25) Zhejiang University has 40000 students and provides 2500 courses. ...

  7. PAT 解题报告 1013. Battle Over Cities (25)

    1013. Battle Over Cities (25) t is vitally important to have all the cities connected by highways in ...

  8. PAT 解题报告 1010. Radix (25)

    1010. Radix (25) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 11 ...

  9. PAT 解题报告 1009. Product of Polynomials (25)

    This time, you are supposed to find A*B where A and B are two polynomials. Input Specification: Each ...

随机推荐

  1. Java——Spring注解

    Spring常用注解使用注解来构造IoC容器用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<context:component-scan bas ...

  2. Less文件的建立

    1.打开DreamWeaver 2.选择 新建 Less       文件名为.less,保存于Less文件夹中 3.声明文档头:@charset "utf-8"; 4.将Less ...

  3. jQuery——jQuery选择器

    基本选择器 # Id选择器 $(“#btnShow”)选择id为btnShow的一个元素 . 类选择器 $(“.liItem”)选择含有类liItem的所有元素 ele 标签选择器 $(“li”)选择 ...

  4. 三角形状的点阵模糊效果iOS源码

    源码FFAngularPointilism,FFAngularPointilism能够将UIImageView像添加滤波器一样生成三角形状的点阵模糊效果.可以通过动画方式来模糊,也可以立刻模糊.另外并 ...

  5. 【译】x86程序员手册10 - 第4章系统架构

    1.1.2 Part II -- Systems Programming 系统编程 This part presents those aspects of the architecture that ...

  6. C# 字符串的入门

    1."@"表示字符串中的"\"不当成转义符. 2.转义符或者特殊处理的一些字符只是针对于代码中直接写出的字符串中,对于程序运行中读取出来的转义符或者特殊处理的字 ...

  7. mvc EF 出现异常, 能提示出那个字段出现问题

    } catch (DbEntityValidationException ex) { message = "添加异常"; desc = " {" + ex.Me ...

  8. asp网站中使用百度ueditor教程.txt

    1.根据网站类型及编码选择相应的ueditor版本,如我的网站编码为gb2312,则选择ueditor 1.43 asp gbk版.2.本机IE浏览器应为8.0或以上,8.0以下的ueditor 1. ...

  9. Luogu P1256 显示图像

    P1256 显示图像 题目描述 古老的显示屏是由N×M个像素(Pixel)点组成的.一个像素点的位置是根据所在行数和列数决定的.例如P(2,1)表示第2行第1列的像素点.那时候,屏幕只能显示黑与白两种 ...

  10. 理解Mysql prepare预处理语句

    MySQL 5.1对服务器一方的预制语句提供支持.如果您使用合适的客户端编程界面,则这种支持可以发挥在MySQL 4.1中实施的高效客户端/服务器二进制协议的优势.候选界面包括MySQL C API客 ...