1082. Read Number in Chinese (25)-字符串处理
题意就是给出9位以内的数字,按照汉子的读法读出来。
读法请看下方的几个例子:
5 0505 0505 伍亿零伍佰零伍万零伍佰零伍
5 5050 5050 伍亿伍仟零伍拾万伍仟零伍拾 (原本我以为这个是读:伍亿伍仟零伍拾万"零"伍仟零伍拾)
5 0550 0055 伍亿零伍佰伍拾万零伍拾伍
5 5005 5500 伍亿伍仟零伍万伍仟伍佰
5 5500 0055 伍亿伍仟伍
按四位四位的分开处理,具体见代码~
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
char number[];
bool first=true;
char str1[][]={"Fu","Yi","Wan"};
char str2[][]={"","Shi","Bai","Qian"};
char digit[][]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"}; /*
cnt表示该位的右边还剩下left-1位(包括该位)
read是4位4位的读
*/
void read(int idx,int left){
if(left==)
return;
if(number[idx]==''){
bool allZero=true; //判断接下来的是否都是0,若都是就不需要读ling
int cnt=;
for(int i=idx;i<idx+left;i++){
if(number[i]!=''){
allZero=false;
break;
}
else
cnt++;
}
if(!allZero){
printf(" ling");
read(idx+cnt,left-cnt);
}
}
else{
if(!first)
printf(" ");
else
first=false;
printf("%s",digit[number[idx]-'']);
if(left>)
printf(" %s",str2[left-]);
read(idx+,left-);
}
}
int main()
{
first=true;
scanf("%s",number);
int len=strlen(number);
int left=len;
int idx=;
int a=atoi(number);
//注意0这个特例!!!,没有考虑这个导致WA
if(a==){
printf("ling");
return ;
}
if(number[]=='-'){
first=false;
printf("Fu");
left--;
idx++;
}
if(left>=){
if(!first){
printf(" ");
}
else
first=false;
printf("%s",digit[number[idx]-'']);
printf(" Yi");
left--;
idx++;
}
//万位上的四位
if(<=left && left<=){
read(idx,left-);
idx+=left-;
left=;
printf(" Wan");
}
//低位上的四位
if(<=left<=){
read(idx,left);
}
return ;
}
1082. Read Number in Chinese (25)-字符串处理的更多相关文章
- 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 ...
- 【PAT甲级】1082 Read Number in Chinese (25 分)
题意: 输入一个九位整数,输出它的汉字读法(用拼音表示). trick: 字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误. AAAAAccepted ...
- 1082 Read Number in Chinese (25分)
// 1082.cpp : 定义控制台应用程序的入口点. // #include <iostream> #include <string> #include <vecto ...
- PAT (Advanced Level) 1082. Read Number in Chinese (25)
模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- pat1082. Read Number in Chinese (25)
1082. Read Number in Chinese (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- A1082 Read Number in Chinese (25 分)
1082 Read Number in Chinese (25 分) Given an integer with no more than 9 digits, you are supposed t ...
- 1082 Read Number in Chinese (25 分)
1082 Read Number in Chinese (25 分) Given an integer with no more than 9 digits, you are supposed to ...
- PAT 1082 Read Number in Chinese[难]
1082 Read Number in Chinese (25 分) Given an integer with no more than 9 digits, you are supposed to ...
- A1082 Read Number in Chinese (25)(25 分)
A1082 Read Number in Chinese (25)(25 分) Given an integer with no more than 9 digits, you are suppose ...
随机推荐
- mysql数据导入导出与数据表优化
一.数据导入 mysqlimport -uroot oa d:/aa.txt --fields-terminated-by=, --fields-optionally-enclosed-by= --l ...
- python3: 文件与IO
1.读写文本数据 # Write chunks of text data with open('somefile.txt', 'wt') as f: f.write(text1) # Redirect ...
- MySQL递归查询父节点或递归查询子节点-陈远波
根据id查询父节点,具体需要修改的地方笔者已在注释中给大家作了注解 DELIMITER $$ USE `yjlc_platform`$$ -- getCompanyParent 为函数名 DROP F ...
- 页面元素固定在页面底部的纯css代码(兼容IE6)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Oracle_spatial的常见错误与注意事项
常见的错误 1.ORA-13226:没有空间索引接口将不被支持 当使用一个空间操作符时,如果没有使用空间索引导致该操作符不能被完成将会返回该错误.这可能会发生在当你使用的列上没有空间索引.或者优化器没 ...
- BZOJ3155:Preprefix sum(线段树)
Description Input 第一行给出两个整数N,M.分别表示序列长度和操作个数 接下来一行有N个数,即给定的序列a1,a2,....an 接下来M行,每行对应一个操作,格式见题目描述 Out ...
- java中Integer与int装箱拆箱一点收获
示例代码: class BoxIntInteger { public static void main(String[] args) { Integer a = new Integer(10111); ...
- 有crontab中的脚本不执行,需要在脚本里面export各种环境变量
[oracle@sta ~]$ vi .bash_profile # .bash_profile # Get the aliases and functionsif [ -f ~/.bashrc ]; ...
- leetcode 26—Remove Duplicates from Sorted Array
Given a sorted array nums, remove the duplicates in-place such that each element appear only once an ...
- jstl 使用
1.需要导入: 1)jstl.jar 2)standard.jar 引入:jsp相应的核心库:<%@taglib prefix="c" uri="http:// ...