PAT (Advanced Level) 1082. Read Number in Chinese (25)
模拟题。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std; string num[]=
{
"ling","yi","er","san","si",
"wu","liu","qi","ba","jiu"
};
string tmp="";
string ans="";
string s=""; string f(string TMP)
{
if(TMP[]==''&&TMP[]==''&&TMP[]==''&&TMP[]=='') return "ling";
string t="";
int p;
for(int i=TMP.length()-;i>=;i--)
if(TMP[i]!='') {p=i; break;} for(int i=;i<=p;i++) t=t+TMP[i]; if(t=="" ) return "ling"; if(t.length()==) return "ling";
if(t.length()==) return num[t[]-''];
if(t.length()==)
{
if(t[]=='') return num[t[]-'']+" Shi";
return num[t[]-'']+" shi "+num[t[]-''];
}
if(t.length()==)
{
if(t[]==''&&t[]=='') return num[t[]-'']+" Bai";
if(t[]==''&&t[]!='') return num[t[]-'']+" Bai "+num[t[]-'']+" Shi";
if(t[]!=''&&t[]=='') return num[t[]-'']+" Bai ling "+num[t[]-''];
if(t[]!=''&&t[]!='') return num[t[]-'']+" Bai "+num[t[]-'']+" Shi "+num[t[]-''];
}
if(t.length()==)
{
if(t[]==''&&t[]==''&&t[]=='') return num[t[]-'']+" Qian";
if(t[]!=''&&t[]==''&&t[]=='') return num[t[]-'']+" Qian ling "+num[t[]-''];
if(t[]==''&&t[]!=''&&t[]=='') return num[t[]-'']+" Qian ling "+num[t[]-'']+" Shi";
if(t[]!=''&&t[]!=''&&t[]=='') return num[t[]-'']+" Qian ling "+num[t[]-'']+" Shi "+num[t[]-''];
if(t[]==''&&t[]==''&&t[]!='') return num[t[]-'']+" Qian "+num[t[]-'']+" Bai";
if(t[]!=''&&t[]==''&&t[]!='') return num[t[]-'']+" Qian "+num[t[]-'']+" Bai ling "+num[t[]-''];
if(t[]==''&&t[]!=''&&t[]!='') return num[t[]-'']+" Qian "+num[t[]-'']+" Bai "+num[t[]-'']+" Shi";
if(t[]!=''&&t[]!=''&&t[]!='') return num[t[]-'']+" Qian "+num[t[]-'']+" Bai "+num[t[]-'']+" Shi "+num[t[]-''];
}
} int main()
{
cin>>tmp;
int len=tmp.length();
for(int i=;i<len/;i++)
swap(tmp[i],tmp[len-i-]); if(tmp[tmp.length()-]=='-') ans=ans+"Fu "; for(int i=;i<tmp.length();i++)
{
if(tmp[i]=='-') continue;
else s=s+tmp[i];
} if(s.length()==)
{
string s1,s2,s3; string g="";
g=g+s[]+s[]+s[]+s[];
s2=f(g); g="";
g=g+s[]+s[]+s[]+s[];
s3=f(g); ans=ans+num[s[s.length()-]-'']+" Yi"; if(s2=="ling") {}
else
{
ans=ans+" ";
if(s[]=='') ans=ans+"ling ";
ans=ans+s2;
ans=ans+" Wan";
} if(s3=="ling"){}
else
{
ans=ans+" ";
if(s[]=='') ans=ans+"ling ";
ans=ans+s3;
}
}
else if(s.length()>=&&s.length()<=)
{
string s2;
string s3; int len=s.length();
for(int i=len;i<;i++) s=s+''; string g;
g=g+s[]+s[]+s[]+s[];
s2=f(g); g="";
g=g+s[]+s[]+s[]+s[];
s3=f(g); ans=ans+s2;
ans=ans+" Wan"; if(s3=="ling"){}
else
{
ans=ans+" ";
if(s[]=='') ans=ans+"ling ";
ans=ans+s3;
} }
else if(s.length()<=)
{
string s3; int len=s.length();
for(int i=len;i<;i++) s=s+''; string g;
g=g+s[]+s[]+s[]+s[];
s3=f(g); ans=ans+s3;
} cout<<ans<<endl; return ;
}
PAT (Advanced Level) 1082. Read Number in Chinese (25)的更多相关文章
- PTA (Advanced Level)1082.Read Number in Chinese
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese ...
- 【PAT甲级】1082 Read Number in Chinese (25 分)
题意: 输入一个九位整数,输出它的汉字读法(用拼音表示). trick: 字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误. AAAAAccepted ...
- PAT (Advanced Level) 1024. Palindromic Number (25)
手动模拟加法高精度. 注意:如果输入数字的就是回文,这个时候输出0步. #include<iostream> #include<cstring> #include<cma ...
- PAT (Advanced Level) Practise - 1094. The Largest Generation (25)
http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...
- 1082. Read Number in Chinese (25)
题目如下: Given an integer with no more than 9 digits, you are supposed to read it in the traditional Ch ...
- 1082. Read Number in Chinese (25)-字符串处理
题意就是给出9位以内的数字,按照汉子的读法读出来. 读法请看下方的几个例子: 5 0505 0505 伍亿零伍佰零伍万零伍佰零伍 5 5050 5050 伍亿伍仟零伍拾万伍仟零伍拾 (原本我以为这个 ...
- 1082 Read Number in Chinese (25分)
// 1082.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <string> #include <vecto ...
- PAT (Advanced Level) 1102. Invert a Binary Tree (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1098. Insertion or Heap Sort (25)
简单题.判断一下是插排还是堆排. #include<cstdio> #include<cstring> #include<cmath> #include<ve ...
随机推荐
- 手机版WEB开发经验分享,手机版网站开发注意事项,网站自适应,手机版网站自适应,移动安卓APP自适应
转自 http://my.oschina.net/cart/blog/282477 做前端开发不短了,用过jQuery Mobile jqMobi 也纯手工写过.. 最后总结如下: jQuery Mo ...
- ECShop - 数据库操作类
ECShop v2.7.2没有使用一些开源的数据库操作类,比如adodb或者PEAR,而是封装了自己的实现.这样做的好处是实现非常轻量,只有一个文件,27Kb,大大减小了分发包的文件大小.另外,当网站 ...
- 当@PathVariable遇上中文和点
当@PathVariable遇上中文和点 Spring MVC从3.0开始支持REST,而主要就是通过@PathVariable来处理请求参数和路径的映射. 由于考虑到SEO的缘故,很多人喜欢把新闻 ...
- User.java 实体类 带 数据库字段模板
package com.tgb.web.controller.entity; import javax.persistence.Column; import javax.persistence.Ent ...
- centos7配置ip
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 ONBOOT=yes 重启ip服务 systemctl restart network.service 开 ...
- Qt之日志输出窗口
来源:http://blog.sina.com.cn/s/blog_a6fb6cc90101guz0.html 继上节所讲,Qt可以很容易的将一些日志信息保存到文件中,那么日志信息如何输出到窗口呢? ...
- libprotobuff8.so not found
http://stackoverflow.com/questions/25518701/protobuf-cannot-find-shared-libraries
- AVFoundation(二)---MPMusicPlayerController
话不多说,直接上代码,代码中详细介绍了如何初始化,并设置一些常用的属性. /** * MPMusicPlayerController用于播放音乐库中的音乐 */ /** * 初始化MPMusicPla ...
- rs.Open sql,conn,0,2,1
例子:rs.Open sql,conn,0,2,1 CursorType = 0,默认值,打开仅向前类型游标.LockType = 2, 开放式锁定Options = 1, 指示 ADO 生成 SQL ...
- JSP简单标签标签库开发
1.定制标签的实现类称为标签处理器,简单标签处理器指实现SimpleTag接口的类,如下图的SimpleTagSupport类,该类为SimpleTag接口的默认实现类. 注:不要直接实现Simple ...