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 ...
随机推荐
- yarn安装node-sass失败问题
注:使用 yarn install 命令安装依赖时报错 第一步:更改镜像源 yarn config set registry https://registry.npm.taobao.org -g 第二 ...
- Unity3d—GUI能量条
1.打开Unity编辑器. 2.在脚本文件夹中添加C#脚本,我的是添加了skill_01这个脚本.(要自己设置文件夹,方便管理,不然文件添乱不方便管理) 3.注意,脚本的名字一旦确定就不要去改动,因为 ...
- Kubectl 的替代品:kubeman
周末闲逛 Twitter 时,发现一个很有意思的小工具叫 kubeman,野心倒是不小,励志成为 kubectl 的替代品,用于实时监控和管理 kubernetes 集群,还可以调试与 Istio 相 ...
- 理解 Virtual DOM(摘)及评价
框架并没有提高web的性能,只是让开发者更加专注的完成业务逻辑,而不用过渡的考虑性能上的优化.如果以性能来比的话,框架是绝对比不过优化后的原生代码的. 二.什么是Virtual DOM Virtual ...
- linux 通过tar直接打包方式 迁移oracle的软件包环境:rdbms/lib/config.c
step1.修改sysctl.conf step2.修改ulimit.conf step3.打包源oracle安装包 step4.通过id{oracle的安装运行用户} 获取安装oracle的[ORA ...
- Logstash之控制台输出的两种方式
输出json output { stdout { codec => json } } 输出rubydebug output { stdout { codec => rubydebug } ...
- 【spring boot】注解@Slf4j的使用
注解@Slf4j的使用 如果不想每次都写 private final Logger logger = LoggerFactory.getLogger(当前类名.class); 可以用注解@Slf4j ...
- Spring.yml配置文件读取字符串出现错误
今天遇到一个诡异的问题,在配置文件中配置了一个值为字符串的属性,但是在用@Value注入时发现注入的值不是我配置的值,而且在全文都没有找到匹配的值 之后研究了好久,发现yml文件会把0开头的数组进行8 ...
- 【转载】C#的ArrayList使用IndexOf方法查找第一个符合条件的元素位置
在C#的编程开发中,ArrayList集合是一个常用的非泛型类集合,在ArrayList集合中如果需要查找第一个符合条件的元素所在的位置,可以使用ArrayList集合的IndexOf方法,Index ...
- itextpdf中表格中单元格的文字水平垂直居中的设置
在使用itextpdf中,版本是5.5.6,使用Doucument方式生成pdf时,设置单元格中字体的对齐方式时,发现一些问题,并逐渐找到了解决方式. 给我的经验就是:看官网的例子才能保证代码的效果, ...