1082. Read Number in Chinese (25)

102 篇文章 0 订阅
26 篇文章 0 订阅

1082. Read Number in Chinese (25)

时间限制
400 ms
内存限制
65536 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
用中文读数字;还带单位的(PS:这算按这种形式的读)
首先这里最多9个数字;
正数不读符号位
负数符号位读Fu
数字读对应的拼音全部小写,对应单位第一个大写,其他小写;
重点一,这种读法如果出现零要处理;1 0000 0000 为 yi Yi;108081 为yi Shi Wan ba Qian ling ba Shi yi;100000001为yi Yi ling yi
重点二,空格要处理;

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户
8月17日 16:25答案正确251082C++ (g++ 4.7.2)1356datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分
0答案正确12489/9
1答案正确13085/5
2答案正确13564/4
3答案正确13003/3
4答案正确13044/4
 
 
#include<iostream>   
#include<string>
using namespace std;   
string returnPinyin(char c)
{
  switch (c)
  { 
  case '0':return "ling\0";
  case '1':return "yi\0";
  case '2':return "er\0";
  case '3':return "san\0";
  case '4':return "si\0";
  case '5':return "wu\0";
  case '6':return "liu\0";
  case '7':return "qi\0";
  case '8':return "ba\0";
  case '9':return "jiu\0"; 
  }
  return "\0";
}
string temindex(int len)/*后面有单位的加空格加单位,没有单位的比如len=1,不加空格不加单位*/
{
  switch (len)
  {
  case 5:return " Wan\0";
  case 9:return " Yi\0";
  }
  switch (len % 4)
  {
  case 0:return " Qian\0";
  case 1:return "\0";
  case 2:return " Shi\0";
  case 3:return " Bai\0";
  } 
  return "\0";
}
int main()
{
  string str;
  string ans;
  int index; 
  int count;
  bool zero;
  cin >> str;
  ans = "\0";
  if (str[0] == '-')
  {
    ans = "Fu \0";
    str.erase(0, 1);
  }
  index = 0;
  zero = false; 
  while (!str.empty())
  { 
        count = 0;
      if (index == 0)
      {
        ans += returnPinyin(str[0]);
        ans += temindex(str.size());
        str.erase(0, 1);
        index++;
      }/*第一个非符号数,用于处理格式,如果前有-,那么这里是- 数 单位;如果前面无-,那么这里数 单位*/
      while (str.size()>0&&str[0] == '0' && str.size() % 4 != 1)
      {
        str.erase(0, 1);
        zero = true;
        count++;
      }
      if (zero&&str.size()>0 && str[0] != '0')/*循环出来有的一种情况10001,100000001需要直接零*/
      { 
          ans += " ling\0";
          zero = false; 
      }  
      if (str.size()>1&&str.size() % 4 == 1 && str[0] == '0'&&count<3)/*循环出来的另一种情况,108181,不需要零,需要单位亿或者万
                                      count用于处理1 0000 0000这个数字不需要单位万*/
      {
          ans +=temindex(str.size());    
      }
      if (str.size() > 0 && str[0] != '0')/*不是第一个也不是零,直接 数 单位 */
      {
        ans += " " + returnPinyin(str[0]); 
        ans +=temindex(str.size());   
      }      
      str.erase(0, 1);
  }
  cout << ans << endl;
    system("pause");
  return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值