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 ...
随机推荐
- CentOS 安装libgdi的方法
1. 安装必须的包 yum install glib2-devel cairo-devel libjpeg-turbo-devel-1.2.90-8.el7.x86_64 libtiff-devel- ...
- tk.mybatis 中一直报...table doesn't exists
首先检查你在实体类中可有加上@Table(name="数据库中的表名") 第二:如果你加了@Table注解, 那么只有一种可能就是.xml中定义了与通用mapper中的相同的方法名 ...
- Prometheus 监控Mysql服务器及Grafana可视化
Prometheus 监控Mysql服务器及Grafana可视化. mysql_exporter:用于收集MySQL性能信息. 使用版本 mysqld_exporter 0.11.0 官方地址 使用文 ...
- maven打包产生可执行jar包
http://blog.csdn.net/u014695188/article/details/53128095 https://blog.csdn.net/fuck487/article/detai ...
- 【spring boot】加载同名Bean解决方法
原文地址:https://blog.csdn.net/liuyueyi25/article/details/83280239 @SpringBootApplication @ComponentScan ...
- tkmybatis VS mybatisplus
本文是简单对比了以下官网上的内容 文章目录 TkMybatis Vs MybatisPlus 1.基础CRUD BaseMapper 2.代码生成器 3. 全局主键 Sequence主键 4. 热加载 ...
- EF Core反向导航属性解决多对一关系
多对一是一种很常见的关系,例如:一个班级有一个学生集合属性,同时,班级有班长.语文课代表.数学课代表等单个学生属性,如果定义2个实体类,班级SchoolClass和学生Student,那么,班级Sch ...
- 阿里OSS前端直传
第一次写博客,如有错误请多多指教. 先上代码吧: ossUpload = function (file, fun, funParameter) { //第一此请求后台服务器获取认证请求 $.ajax( ...
- C#安全类型转换基于convert
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Globalization; n ...
- 4-rocketmq 发送时异常:system busy 和 broker busy 解决方案
原文:https://www.cnblogs.com/enenen/p/10138511.html 推荐阅读:https://juejin.im/post/5d996285f265da5bad4052 ...