pat解题报告【1082】
来源:互联网 发布:细川忠兴 知乎 编辑:程序博客网 时间:2024/05/18 01:24
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;}
0 0
- pat解题报告【1082】
- PAT解题报告索引
- PAT-1010解题报告
- PAT-1021解题报告
- PAT 解题报告
- pat解题报告【1076】
- pat解题报告【1073】
- pat解题报告【1078】
- pat解题报告【1074】
- PAT解题报告A1111
- PAT解题报告A1087
- PAT乙级解题报告目录
- 解题报告-PAT-List Leaves
- 解题报告-PAT-File Transfer
- PAT甲级解题报告汇总
- PAT (Top Level) 解题报告
- PAT 1003:Emergency解题报告
- PAT乙级解题报告索引
- 是理科的关键看机会了如今也已
- 用SecureCRT来上传和下载文件
- drbd
- Java高新技术—类的加载和初始化
- Redis缓存系统(1)Java-Jedis操作Redis,基本操作以及 实现对象保存
- pat解题报告【1082】
- HDU1159:Common Subsequence(LCS)
- 人生就像公交车——真的很经典
- Hive基础之Hive是什么以及Hive使用场景
- iOS 面试题(十一)
- 反对你是否古典美过的好吗姑妈大规模
- 复杂链表的复制
- 最牛B的编码套路
- SQL Server set nocount on 与JDBC: The statement did not return a result