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. 将子节点的所有父节点ID合并成一个字符串,并更新表

    begin for cur_dept in (select SLCATALOG_ID from T_GIS_SLCATALOG) loop UPDATE T_GIS_SLCATALOG SET PAT ...

  2. node.js安装步骤

    首先这是node.js的官网:https://nodejs.org/en/ 截至2017年12月9日,node更新在8.9.3该版本,建议开发人员下载6.0以上版本,8以上不是很稳定!  如果有其他需 ...

  3. eclipse整合maven下载jar包速度慢问题解决

    引用:http://blog.csdn.net/u010154380/article/details/70339538 开发过程中在pom.xml中添加pom的时候,默认是需要从中央仓库中下载,但是下 ...

  4. Linux 查询PID和端口号

    https://www.cnblogs.com/understander/p/5546458.html

  5. HDU_1542_线段树【扫描线】

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  6. Mysql 之主从复制,mysql-proxy读写分离

    准备两台mysql服务器,master(192.168.43.64).slave(192.168.84.129) master配置: log-bin=mysql-bin binlog_format=m ...

  7. Ubuntu 18.04 安装chrome浏览器

    参考 https://blog.csdn.net/cyem1/article/details/86297197 一分钟安装教程! 1.将下载源加入到系统的源列表(添加依赖) sudo wget htt ...

  8. 微信小程序video

    1.video是原生组件原生组件的层级是最高的,想要覆盖在video上,只能用cover-view 和 cover-image 组件,这2个可以无限嵌套.适用场景:给视频加标题: 2.检测video播 ...

  9. %2d

    %2d是C语言中printf函数的输出格式说明符. 具体解释如下: 使输出的int型的数值以2位的固定位宽输出.如果不足2位,则在前面补空格:如果超过2位,则按实际位数输出. 注:如果输出的数值不是i ...

  10. spring IOC bean间关系

    1.0 继承关系 实体 package com.java.test5; import java.util.*; /** * @author nidegui * @create 2019-06-22 1 ...