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 ...
随机推荐
- Tomcat基础操作
1.在WebApps ROOT目录里,如果删除过ROOT从新创建,放置index.html,index.jsp即可访问. 2.修改默认8080端口,打开server.xml,将8080端口修改为80即 ...
- postgresql NUMERIC(precision, scale)
- rsync用法
前提条件:本机和172.16.93.0配置ssh,进行免密登录 1.基于ssh的rsync远程同步数据(推) rsync -e -SNAPSHOT.jar 172.16.93.0:/data/java ...
- DateTime的ToString方法格式
新建一个.NET Core控制台项目,敲入如下代码: using System; namespace NetCoreDatetime { class Program { static void Mai ...
- 剑指Offer_Java_顺时针打印矩阵(二维数组)
顺(逆)时针打印矩阵 算法思想: 简单来说,就是不断地收缩矩阵的边界 定义四个变量代表范围,up(初始0).down(初始-行高).left(初始-0).right(初始-列宽), 向右走存入整行的值 ...
- K8S CoreDNS部署失败,发现的一个问题
K8S CoreDNS部署失败,查看错误日志,提示如下 root >> kubectl get all --all-namespaces -o wide root >> kub ...
- Delphi - Delphi7 调用阿里大于实现短信消息验证
阿里大于是阿里通信旗下产品,融合了三大运营商的通信能力,提供包括短信.语音.流量直充.私密专线.店铺手机号等个性化服务.每条四分五,价钱还算公道,经老农测试,响应速度非常快,基本上是秒到.官方文档提供 ...
- Python——Scrapy爬取链家网站所有房源信息
用scrapy爬取链家全国以上房源分类的信息: 路径: items.py # -*- coding: utf-8 -*- # Define here the models for your scrap ...
- Gin-Go学习笔记六:Gin-Web框架 Api的编写
Api编写 1> Gin框架的Api返回的数据格式有json,xml,yaml这三种格式.其中yaml这种格式是一种特殊的数据格式.(本人暂时没有实现获取节点值得操作) 2> ...
- 用jTessBoxEditorFX训练字库
软件下载:https://sourceforge.net/projects/vietocr/files/jTessBoxEditor/ 官方字库下载:https://github.com/tesser ...