583

# 题目

1234567890987654321123456789

yi san wu

# 解析

Python不考虑效率的话，可以很短

# 代码

## C++解法

#include <cstdio>
#include<cstring>
const int maxn = 105;
char s[maxn];

char pinyin[10][5] = {"ling", "yi",  "er", "san", "si",
"wu",   "liu", "qi", "ba",  "jiu"};

int numStack[maxn];

void toPinyin(int num) {
int stackPos = 0;
while (num) {
numStack[stackPos++] = num % 10;
num /= 10;
}
for (int i = stackPos - 1; i >= 0; --i) {
printf("%s", pinyin[numStack[i]]);
if (i)
printf(" ");
}
printf("\n");
}

int main() {
scanf("%s", s);
int l = strlen(s);
int ans = 0;
for (int i = 0; i < l; ++i) {
ans += s[i] - '0';
}
toPinyin(ans);
return 0;
}

## Python解法

pinyin = ["ling", "yi",  "er", "san", "si", "wu",   "liu", "qi", "ba",  "jiu"]
print(" ".join([pinyin[int(i)] for i in str(sum([int(i) for i in input()]))]))

## Java解法

import java.util.ArrayList;
import java.util.Scanner;

class Main {
static Scanner in;

static String[] pinyin = { "ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu" };

public static void getPinYin(int n) {
ArrayList<String> output = new ArrayList<String>();
while (n > 0) {
n /= 10;
}

boolean first = true;
for (String i : output) {
if (first == true)
first = false;
else
System.out.print(" ");
System.out.print(i);
}
System.out.print("\n");
}

public static void main(String args[]) {
in = new Scanner(System.in);
String s = in.next();
int sum = 0;
for (int i = 0; i < s.length(); ++i)
sum += s.charAt(i) - '0';
getPinYin(sum);
in.close();
}
}

• 点击查看/关闭被识别为广告的评论