pat解题报告【1082】
1082. Read Number in Chinese (25)
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.
-123456789
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
100800
yi Shi Wan ling ba Bai
// 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】的更多相关文章
- PAT 解题报告 1052. Linked List Sorting (25)
1052. Linked List Sorting (25) A linked list consists of a series of structures, which are not neces ...
- 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 ...
- PAT 解题报告 1050. String Subtraction (20)
1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...
- PAT 解题报告 1049. Counting Ones (30)
1049. Counting Ones (30) The task is simple: given any positive integer N, you are supposed to count ...
- PAT 解题报告 1048. Find Coins (25)
1048. Find Coins (25) Eva loves to collect coins from all over the universe, including some other pl ...
- PAT 解题报告 1047. Student List for Course (25)
1047. Student List for Course (25) Zhejiang University has 40000 students and provides 2500 courses. ...
- PAT 解题报告 1013. Battle Over Cities (25)
1013. Battle Over Cities (25) t is vitally important to have all the cities connected by highways in ...
- PAT 解题报告 1010. Radix (25)
1010. Radix (25) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 11 ...
- 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 ...
随机推荐
- C语言标准库头文件
<assert.h><complex.h><ctype.h><errno.h><fenv.h><float.h><intt ...
- android黑科技系列——解析公众号文章消息和链接文章消息自动打开原理
一.辅助功能方案分析 关于WX的各种功能插件已经非常普遍了,而现在的插件都是依赖于Xposed框架进行的,所以个人觉得WX应该在这方便应对Xposed框架的使用防护,防止插件满天飞的现象,本文来介绍一 ...
- js-消息对话框
最近在某技术网站学习一些js(JavaScript)的课程,将笔记分享一下 消息对话框1. **alert **消息对话框,输出内容,可以是字符串或变量,与document.write 相似 va ...
- SQL Server 中4个系统数据库,Master、Model、Msdb、Tempdb。
(1)Master数据库是SQL Server系统最重要的数据库,它记录了SQL Server系统的所有系统信息.这些系统信息包括所有的登录信息.系统设置信息.SQL Server的初始化信息和其他系 ...
- JS——筋斗云案例
需求: 1.鼠标移动到哪里,云彩移动到哪里 2.鼠标离开,云彩回到原点 3.鼠标离开,云彩回到之前点击的地方 <!DOCTYPE html> <html lang="en& ...
- 用sed替换含反斜(\)的字符串
今天在linux替换配置文件时,test文件里有一个字符串 e:\ 需要换成/usr/home/ 用了sed命令:sed -i "s?e:\\?/usr/home/?g" test ...
- ubuntu14.3安装phpmyadmin
一.安装 sudo apt-get install phpmyadmin 二.软连接 cd /var/www/html/ sudo ln -s /usr/share/phpmyadmin phpmya ...
- Lazarus 1.44升级到1.6 UTF8处理发生变化了
首先这里真的要强调一下,由于Freepascal升级到3.0后,FPC的内部将整个代码处理由AnsiString改为了UTF8编码(RTL with default codepage UTF-8). ...
- FTP工作原理
FTP工作原理 FTP两种传输方式:1.ASCII传输2.二进制传输 FTP主被动原理: 主动方式:1.用户与服务器建立控制通道2.客户端发出PORT指令,主动告诉服务器端口号3.服务器主动通过20端 ...
- 为.net mvc core 启用 https
引用nuget包:Microsoft.AspNetCore.Server.Kestrel.Https这是一个服务器测试ssl密钥,密码如代码里面所示 using System; using Syste ...