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 ...
随机推荐
- PHP中GD库安装
安装gd库扩展不能像其他扩展安装一样,直接./configure --prefix=/xxx 还需要激活png,jpeg,字库等支持 ./configure --prefix=/xxx --with- ...
- Django Template模板
Django Template 你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python 代码之中. 下面我们来调用html views def ind ...
- Spring 读取XML配置文件的两种方式
import org.springframework.context.ApplicationContext; import org.springframework.context.support.Cl ...
- 简单粗暴的“Debug模式”
在项目中,通常会遇到:调试程序和程序在线上运行时程序运行的参数不一样, 例如线上运行时程序是获取线上的机器的ip,而调试程序时,我们会指定一个ip进行调试. 又或者项目要与多个系统进行数据交换,调试的 ...
- 【servlet】 过滤器模板
EncodingFilter.java package Filter; import java.io.IOException; import javax.servlet.Filter; import ...
- 多线程junit单元测试
junit中测试完成后会进行jvm退出,而不是线程退出,所以任一线程退出都会导致测试结束,junit想进行多线程测试需要进行另外包装,网上看到一个投机取巧的例子还不错,贴上我的测试代码(代码中我需要测 ...
- Goods transportation
Goods transportation time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 创建zend framework 项目要注意的
1.必须要设置变量环境 我的电脑右击-属性-高级-环境变量 则在环境变量中添加 变量名:PATH 环境值:D:\phpserver\php5.4;D:\ZendFramework\bin 把php.e ...
- SimplePath 使用心得
上图是 用SimplePath 做的 寻路,其中 三个 绿点 是 移动的 目标点,三个红点 是 角色移动,蓝色方块是阻挡物体. 这三个角色 移动 有三种 方式,1 随机移动2 按照 绿色小球点 移动 ...
- C4.5算法总结
C4.5是一系列用在机器学习和数据挖掘的分类问题中的算法.它的目标是监督学习:给定一个数据集,其中的每一个元组都能用一组属性值来描述,每一个元组属于一个互斥的类别中的某一类.C4.5的目标是通过学习, ...