PAT (Basic Level) Practice (中文)1002 写出这个数 (20 分)

时间:2022-07-26
本文章向大家介绍PAT (Basic Level) Practice (中文)1002 写出这个数 (20 分),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1002 写出这个数 (20 分)

读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。

输入格式:

每个测试输入包含 1 个测试用例,即给出自然数 n 的值。这里保证 n 小于 10​100​​。

输出格式:

在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。

输入样例:

1234567890987654321123456789

输出样例:

yi san wu

水题~

// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<unordered_set>
#define rg register ll
#define inf 2147483647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 300005
#define lb(x) (x&(-x))
const double eps = 1e-6;
using namespace std;
inline ll read()
{
	char ch = getchar(); ll s = 0, w = 1;
	while (ch < 48 || ch>57) { if (ch == '-')w = -1; ch = getchar(); }
	while (ch >= 48 && ch <= 57) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
	return s * w;
}
inline void write(ll x)
{
	if (x < 0)putchar('-'), x = -x;
	if (x > 9)write(x / 10);
	putchar(x % 10 + 48);
}
string s;
ll sum=0,a[maxn],tot;
string p[20]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu","shi"};
int main()
{
    cin>>s;
    for(rg i=0;s[i];i++)
    {
        sum+=s[i]-'0';
    }
    while(sum)
    {
        a[++tot]=sum%10;
        sum/=10;
    }
    for(rg i=tot;i>=1;i--)
    {
        i==1?cout<<p[a[i]]:cout<<p[a[i]]<<" ";
    }
   	return 0;
}