// 1082.cpp : 定义控制台应用程序的入口点。
// #include <iostream>
#include <string>
#include <vector>
using namespace std;
string str;
string s1[4] = { "Ge","Shi","Bai","Qian" };
string s2[10] = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu" };
vector<string> rs, t;
int main()
{
    int n;
    cin >> n;
    if (n<0)
        cout << "Fu ";
    else if (n == 0) {
        cout << "ling"; /*一个零特判*/
        return 0;
    }
    str = to_string(abs(n));
    int len = str.size();
    for (int i = 0; i < len; i++) {
        rs.push_back(s2[str[i] - '0']);
        int pos = len - i - 1;
        if (pos % 4 && str[i] != '0') /* 0十->0*/
            rs.push_back(s1[pos % 4]);
        if (pos == 4)
            rs.push_back("Wan"); /*到万位加万,亿位加亿*/
        if (pos == 8)
            rs.push_back("Yi");
    }
    for (int i = 0; i < rs.size(); i++) {
        t.push_back(rs[i]);
        if (i != 0 && rs[i] == "ling"&&rs[i - 1] == "ling") /*删除连续的零为一个零*/
            t.pop_back();
    }
    t.push_back("Wan");
    for (int i = 0; i < t.size()-1; i++) {
        if (t[i] == "ling" && t[i + 1] == "Wan" )/*删除单个不需要的零如有1000->yi qian ling->yi qian*/
            continue;
        if (i != 0)
            cout << " ";
        cout << t[i];
    }
    return 0;
}
https://pintia.cn/problem-sets/994805342720868352/problems/994805385053978624

1082 Read Number in Chinese (25分)的更多相关文章

  1. 【PAT甲级】1082 Read Number in Chinese (25 分)

    题意: 输入一个九位整数,输出它的汉字读法(用拼音表示). trick: 字符串数组""其实会输出一个空格,而不是什么都不输出,导致测试点0和4格式错误. AAAAAccepted ...

  2. 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 ...

  3. 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 ...

  4. 1082. Read Number in Chinese (25)-字符串处理

    题意就是给出9位以内的数字,按照汉子的读法读出来. 读法请看下方的几个例子: 5 0505 0505 伍亿零伍佰零伍万零伍佰零伍 5 5050 5050 伍亿伍仟零伍拾万伍仟零伍拾  (原本我以为这个 ...

  5. PAT (Advanced Level) 1082. Read Number in Chinese (25)

    模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  6. pat1082. Read Number in Chinese (25)

    1082. Read Number in Chinese (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Redis非关系型缓存数据库集群部署、参数、命令工具

    <关系型数据库与非关系型数据库> 关系数据库:mysql.oracle.DB2.SQL Server非关系数据库:Redis(缓存数据库).MongodDB(处理海量数据).Memcach ...

  2. sqlldr总结参数介绍

    有效的关键字: userid --    ORACLE username/password control -    控制文件 log -        记录的日志文件 *            表示 ...

  3. spring 配置

    在context中配置 如:在base-package指明一个包: <context:component-scan base-package="cn.edu.dao"/> ...

  4. C++算法导论第九章O(n)期望选择序列第i小的数字

    #include<iostream> #include<vector> #include<algorithm> #include<time.h> usi ...

  5. Jquery获取html参数, jquery.params.js 获取参数

    ================================ ©Copyright 蕃薯耀 2019年12月31日 http://fanshuyao.iteye.com/ /** * 使用:$.q ...

  6. php操作shee学习笔记之(一)PHP操作shell函数

    一.php操作shell 1.system函数:执行普通命令 string system (string $command [,int &$return_var]) 1)$command是命令 ...

  7. Eclipse C++配置静态链接库和动态链接库

    转:https://blog.csdn.net/iteye_20658/article/details/82650699 1.动态库: 一.创建动态链接库1.创建工程new->project-& ...

  8. Android学习10

    SharedPreferences 今天练习了利用SharedPreferences保存登录用户名密码: layout布局: <?xml version="1.0" enco ...

  9. Atcoder Beginner Contest151E(排列组合)

    排列组合 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ; ]; long lo ...

  10. iptables详解(2):四表五链

    关于iptables中“四表五链”,我们今天来好好唠唠: 1.表的概念: 我们把具有相同功能的规则的集合叫做"表",所以说,不同功能的规则,我们可以放置在不同的表中进行管理,而ip ...