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;
}

 
 

最新文章

  1. FTP上传文件提示550错误原因分析。
  2. Mac下用brew安装nginx
  3. 某篇ctr预估ppt的链接
  4. Hibernate 中出现 XXXX is not mapped 问题
  5. poj 3841 Double Queue (AVL树入门)
  6. [转载]AxureRP 7超强部件库下载
  7. LDAP过滤器使用说明(用户、组和容器的默认 LDAP 过滤器和属性)
  8. Vim Vundle 插件管理器
  9. Qt入门(2)——使用Qt编写的Hello world
  10. 生产环境使用Nginx+uwsgi部署Django
  11. MyEclipse修改默认的workspace路径
  12. IronPython .NET Integration官方文档翻译笔记
  13. RTSP-RTMP-HLS媒体播放管理
  14. JAVAEE 第八周
  15. HOW TO ANSWER: Tell Me About Yourself
  16. gentoo 建立本地软件库并安装软件 Custom repository
  17. 更新32位Spyder从3.0.0-&gt; 3.2.3
  18. JAVA EXAM2 复习提纲
  19. IIS并发连接数和数据库连接池
  20. 55. 45. Jump Game II *HARD*

热门文章

  1. 如何调用com组件中包含IntPtr类型参数的函数
  2. Java中 == 和 equals()
  3. JDBC链接数据库步骤
  4. PHP操作Redis相关函数
  5. groupbox
  6. 聊聊JS动画库:Velocity.js
  7. ubuntu14.04禁用USB外存储设备
  8. Python培训时长多久可以学会?马哥教育9年经验之谈
  9. vue项目的路由配置
  10. MySQL5.7本地首次登录win10报错修改