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. C语言标准库头文件

    <assert.h><complex.h><ctype.h><errno.h><fenv.h><float.h><intt ...

  2. android黑科技系列——解析公众号文章消息和链接文章消息自动打开原理

    一.辅助功能方案分析 关于WX的各种功能插件已经非常普遍了,而现在的插件都是依赖于Xposed框架进行的,所以个人觉得WX应该在这方便应对Xposed框架的使用防护,防止插件满天飞的现象,本文来介绍一 ...

  3. js-消息对话框

    最近在某技术网站学习一些js(JavaScript)的课程,将笔记分享一下 消息对话框1. **alert **消息对话框,输出内容,可以是字符串或变量,与document.write 相似   va ...

  4. SQL Server 中4个系统数据库,Master、Model、Msdb、Tempdb。

    (1)Master数据库是SQL Server系统最重要的数据库,它记录了SQL Server系统的所有系统信息.这些系统信息包括所有的登录信息.系统设置信息.SQL Server的初始化信息和其他系 ...

  5. JS——筋斗云案例

    需求: 1.鼠标移动到哪里,云彩移动到哪里 2.鼠标离开,云彩回到原点 3.鼠标离开,云彩回到之前点击的地方 <!DOCTYPE html> <html lang="en& ...

  6. 用sed替换含反斜(\)的字符串

    今天在linux替换配置文件时,test文件里有一个字符串 e:\ 需要换成/usr/home/ 用了sed命令:sed -i "s?e:\\?/usr/home/?g" test ...

  7. ubuntu14.3安装phpmyadmin

    一.安装 sudo apt-get install phpmyadmin 二.软连接 cd /var/www/html/ sudo ln -s /usr/share/phpmyadmin phpmya ...

  8. Lazarus 1.44升级到1.6 UTF8处理发生变化了

    首先这里真的要强调一下,由于Freepascal升级到3.0后,FPC的内部将整个代码处理由AnsiString改为了UTF8编码(RTL with default codepage UTF-8). ...

  9. FTP工作原理

    FTP工作原理 FTP两种传输方式:1.ASCII传输2.二进制传输 FTP主被动原理: 主动方式:1.用户与服务器建立控制通道2.客户端发出PORT指令,主动告诉服务器端口号3.服务器主动通过20端 ...

  10. 为.net mvc core 启用 https

    引用nuget包:Microsoft.AspNetCore.Server.Kestrel.Https这是一个服务器测试ssl密钥,密码如代码里面所示 using System; using Syste ...