PATA1082Read Number in Chinese
- 有几点需要注意的地方一是将right转化为与left在在同一节
while (left + 4 <= right)
{
right -= 4;//每次将right移动4位,直到left与right在同一节
}
- 二是输出的时候每一节中的位,以及后面的亿和万
参考代码:
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstring>
#include<cstdlib>
char num[10][5] = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu" };
char wei[5][5] = { "Shi","Bai","Qian","Wan","Yi" };
int main()
{
char str[15];
scanf("%s", str);//按字符串输入数字
int len = strlen(str);
int left = 0, right = len - 1;//分别指向字符串的首尾元素
if (str[0] == '-')
{
printf("Fu");
left++;
}
while (left + 4 <= right)
{
right -= 4;//每次将right移动4位,直到left与right在同一节
}
while (left < len)
{
bool flag = false;//flag==false表示没有累计的0
while (left <= right)
{
if (left > 0 && str[left] == '0')
{
flag = true;
}
else
{
if (flag == true)
{
printf(" ling");
flag = false;
}
if (left > 0) printf(" ");//只要不是首位都要在每个后面输出空格
printf("%s", num[str[left] - '0']);//输出当前位数字
if (left != right)
{
printf(" %s", wei[right - left - 1]);
}
}
left++;
}
if (right != len - 1)
{
printf(" %s", wei[(len - 1 - right) / 4 + 2]);
}
right += 4;
}
system("pause");
return 0;
}
PATA1082Read Number in Chinese的更多相关文章
- PAT1082:Read Number in Chinese
1082. Read Number in Chinese (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 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 ...
- 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)(25 分)
A1082 Read Number in Chinese (25)(25 分) Given an integer with no more than 9 digits, you are suppose ...
- 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)
题目如下: Given an integer with no more than 9 digits, you are supposed to read it in the traditional Ch ...
- A1082. Read Number in Chinese
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese ...
- 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 ...
随机推荐
- solr常见错误
这两天给客户部署独立的solr服务器遇到的错误,现在总结一下. 1. org.apache.solr.client.solrj.SolrServerException: Error executing ...
- 并行 Webclient(一)
在 Stackoverflow 上看到了一个提问,关于并行的 WebClient,觉得回答者的代码很有参考性,下面记录一下,以便日后用到: 提问者: 我有一个功能基本上分为两个子功能. html=Re ...
- Python转义序列
正则表达式参考:https://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html
- MongoDB 学习笔记 ---创建用户
MongoDB安装好了之后,开始学习常用命令 首先,运行MongoDB, 记住,先不用带参数--auth /usr/local/mongodb/bin/mongod -dbpath=/usr/loca ...
- [转] Nginx配置中的location、root、alias
Nginx配置中的location.root.alias location & root 初始配置 [root@adailinux vhost]# cat rio.conf server { ...
- 2019-11-29-C#-性能分析-反射-VS-配置文件-VS-预编译
原文:2019-11-29-C#-性能分析-反射-VS-配置文件-VS-预编译 title author date CreateTime categories C# 性能分析 反射 VS 配置文件 V ...
- 2019-11-29-dotnet-通过-WMI-获取指定进程的输入命令行
原文:2019-11-29-dotnet-通过-WMI-获取指定进程的输入命令行 title author date CreateTime categories dotnet 通过 WMI 获取指定进 ...
- C# 身份证号码15位和18位验证
/// <summary> /// 身份证 /// </summary> [Serializable] public class IDCard { /// <su ...
- SqlDbx连接oracle(无需安装Oracle客户端)
下载地址:https://download.csdn.net/download/xzplinke/10428957 解压SqlDbx.zip,将SqlDbx放到C:盘根目录(C:\SqlDbx 路径是 ...
- PIE SDK栅格矢量化算法
1.算法功能简介 栅格数据矢量化较为复杂,如果由一幅扫描的数字化地图来建立矢量数据库,则需要经过数字图象处理,如边缘增强.细化.二值化.特征提取及模式识别才能获得矢量数据.人们通常将多色地图分色后逐个 ...