当前位置: 首页 > news >正文

pat解题报告【1082】

1082. Read Number in Chinese (25)

时间限制  
400 ms
内存限制  
32000 kB
代码长度限制  
16000 B
判题程序    
Standard    
作者    
CHEN, Yue

Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way.  Output "Fu" first if it is negative.  For example, -123456789 is read as "Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu".  Note: zero ("ling") must be handled correctly according to the Chinese tradition.  For example, 100800 is "yi Shi Wan ling ba Bai".

Input Specification:

Each input file contains one test case, which gives an integer with no more than 9 digits.

Output Specification:

For each test case, print in a line the Chinese way of reading the number.  The characters are separated by a space and there must be no extra space at the end of the line.

Sample Input 1:
-123456789
Sample Output 1:
Fu yi Yi er Qian san Bai si Shi wu Wan liu Qian qi Bai ba Shi jiu
Sample Input 2:
100800
Sample Output 2:
yi Shi Wan ling ba Bai
 
简单的模拟。仅仅是过程描写叙述有点啰嗦。
首先这句话什么意思  Note: zero ("ling") must be handled correctly according to the Chinese tradition
什么叫Chinese tradition,事实上就是对0的特殊处理。
【1】尾部的0不发音
【2】多个连续的0,仅仅发一个音
【3】多个不连续的0。都要发音
【4】大于4位的数肯定要发 Wan 音
【5】大于8位的数一定要发 Yi 音
并且还有个规律: Shi Bai Qian 这三个音循环出现。

 
Ac代码:
 
// pat-1082.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include "iostream"
#include "string"
#include "algorithm"
#include "vector"
#include "stack"

using namespace std;
stack<string> ans;
string num[]={"ling", "yi" ,"er" , "san" , "si" ,  "wu",  "liu" , "qi",  "ba",  "jiu"};
string pos[]={ "Shi","Bai","Qian", "Wan","Yi" };
int main()
{
	long int n=0;
	bool firstout=true;
	cin>>n;
	if (n==0)
	{
		cout<<"ling";
		goto end;
	}
	if (n<0)
	{   
		cout<<"Fu";
		firstout=false;
		n=-(n);
	}
	int cnt=0;
	bool wan_flag=false;
	bool zero=false;
	bool first=true;
	while(n)
	{
	  int temp=n%10;
	  //0 特殊处理
	  if (temp==0)
	  { 
		  if (cnt==3)
		  {
			  wan_flag=true;
		  }
		  n/=10;
		  if (!first)
		  {  
			  cnt++;
		  }
	      first=false;
		  if (zero)//第一次遇到0
		  {
			  ans.push(num[0]);
			  zero=false;
			  continue;
		  }
		  else
		  {
			  continue;
		  }
	  }
	  zero=true;
	  if(first)//忽略个位
	  {
		    ans.push(num[temp]);//yi er san si ~~~~~
			 n/=10;
			  first=false;
			 continue;
	  }
	 if(cnt<7)
	 {  
		 if (wan_flag)
		 {
			 wan_flag=false;
			 ans.push(pos[3]);
		 }
	     ans.push(pos[cnt%4]);//shi bai qian wan 
	  }
	 else
     {
	  ans.push(pos[4]);//yi
	 }
	 
	  ans.push(num[temp]);//yi er san si ~~~~~
	 
	  n/=10;
	  cnt++;
	 
	}
	while (!ans.empty())
	{
		string temp=ans.top();
		ans.pop();
		if (firstout)
		{
			firstout=false;
			cout<<temp;
			continue;
		}
		cout<<" "<<temp;
	}
end:	return 0;
}


 
 

相关文章:

  • Java IO详解(七)------随机访问文件流
  • Spring+SpringMVC+MyBatis深入学习及搭建(三)——MyBatis全局配置文件解析
  • 硬链接和软链接
  • 【python自制】让大白成为你的个人助手!
  • java RabbitMQ
  • linux 21的用法
  • shell脚本编程30分钟入门上手
  • 跟着实例学习ZooKeeper的用法: Leader选举
  • R语言数据可视化2—ggplot2各种维度的业务量统计根据类型统计不同月份的业务量...
  • 使用InteliJ IDEA导出jar包执行报错:找不到主清单属性
  • Ubuntu14.04下sogou输入法的输入框只显示英文不显示中文的问题
  • CentOS 7 更新源 – 使用国内 163 yum 源
  • Linux 的五个重启命令及具体说明
  • 蓝桥杯练习
  • C# 单元测试,带你快速入门
  • -------------------- 第二讲-------- 第一节------在此给出链表的基本操作
  • 自己简单写的 事件订阅机制
  • Angular Elements 及其运作原理
  • Codepen 每日精选(2018-3-25)
  • Docker 笔记(2):Dockerfile
  • node.js
  • Solarized Scheme
  • Theano - 导数
  • ⭐ Unity 开发bug —— 打包后shader失效或者bug (我这里用Shader做两张图片的合并发现了问题)
  • v-if和v-for连用出现的问题
  • 动态魔术使用DBMS_SQL
  • 关于字符编码你应该知道的事情
  • 利用jquery编写加法运算验证码
  • 前端代码风格自动化系列(二)之Commitlint
  • 前端设计模式
  • 嵌入式文件系统
  • 如何使用Mybatis第三方插件--PageHelper实现分页操作
  • 腾讯大梁:DevOps最后一棒,有效构建海量运营的持续反馈能力
  • 用jquery写贪吃蛇
  • 2017年360最后一道编程题
  • 格斗健身潮牌24KiCK获近千万Pre-A轮融资,用户留存高达9个月 ...
  • 国内开源镜像站点
  • ​LeetCode解法汇总1276. 不浪费原料的汉堡制作方案
  • #include
  • #单片机(TB6600驱动42步进电机)
  • (4)事件处理——(6)给.ready()回调函数传递一个参数(Passing an argument to the .ready() callback)...
  • (6)添加vue-cookie
  • (javascript)再说document.body.scrollTop的使用问题
  • (Java实习生)每日10道面试题打卡——JavaWeb篇
  • (pytorch进阶之路)扩散概率模型
  • (ZT)一个美国文科博士的YardLife
  • (二)七种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (附源码)计算机毕业设计SSM基于健身房管理系统
  • (三)Hyperledger Fabric 1.1安装部署-chaincode测试
  • (原创)攻击方式学习之(4) - 拒绝服务(DOS/DDOS/DRDOS)
  • .bat批处理(六):替换字符串中匹配的子串
  • .NET DataGridView数据绑定说明
  • .NET 编写一个可以异步等待循环中任何一个部分的 Awaiter
  • .NET/ASP.NETMVC 大型站点架构设计—迁移Model元数据设置项(自定义元数据提供程序)...
  • .netcore如何运行环境安装到Linux服务器