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 ...
随机推荐
- 基于word2vec的文档向量模型的应用
基于word2vec的文档向量模型的应用 word2vec的原理以及训练过程具体细节就不介绍了,推荐两篇文档:<word2vec parameter learning explained> ...
- Prometheus 编写告警规则案例
Prometheus 编写告警规则案例 注:确保alertmanager配置完毕! 1.创建编辑文件:vim /usr/local/prometheus/rules/node.yml # groups ...
- Java : JavaWeb和Tomcat相关
部署:1.直接把项目移动到webapps文件夹下, 用文件夹名访问(如果ROOT文件夹可以直接访问)2.也可以把war包放到webapps文件夹下, tomcat自动解压,但是删除war包必须要停止t ...
- CSS之flex布局和边框阴影
flex布局 main axis:主轴:cross axis:交叉轴 容器的子元素自动成为容器成员,成为flex 项目(item) flex容器属性 flex-direction 该属性决定主轴的 ...
- USE11 上oracle11导入数据中文乱码
分类专栏: 数据库 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/suqimm/artic ...
- VS2019无法安装Android SDK 28的问题
在一台新电脑上安装VS2019,新建Xamarin.Android项目,反复提示要安装Android SDK Build Tools 28.0.3,在弹出的窗口里点击接受协议,却无法安装SDK. 直接 ...
- NoSql的对比以及键值对的存储方式(为什么速度特别快)
什么是NoSql NoSQL(Not Only SQL),泛指非关系型的数据库,是对不同于传统的关系型数据库的数据库管理系统的统称,强调Key-Value Stores和文档数据库的优点.为了解决大规 ...
- dataGridView1_RowEnter事件与dataGridView1.CurrentRow一起使用错误问题
在使用DataGridView想在选项行发生改变时获得当前行的,于是使用了RowEnter 但是获得数据却不对,总是获得前一个被选中的行,比如第一次选中谭经理,再选中王海霞,数据得到却是谭经理的 从事 ...
- 安装oracle时出现的问题
数据库引擎和几个功能安装失败后 ,重新再装还是一样,好不容易全部功能装完成后结果发现登录不了oracle!!!!!!!!!!!!! 气死人,搞了一上午才发现原来是微软账号在搞事,登录本地管理员账户就 ...
- .Net Core部署Linux系统(CentOS7.6)
.net core版本:2.2 Linux:CentOS 7.6 所需工具: Xshell 6 + Xftp 6 第一步:在Startup类中加入这两行代码 然后本地发布项目: 第二步,安装.Net ...