NC215092. 念数字
描述
输入描述
一个整数 x(在int范围内).
输出描述
在一行中输出这个整数对应的拼音,每个数字的拼音之间用空格分开,如"yi er san si"。
示例1
输入:
0
输出:
ling
示例2
输入:
100
输出:
yi ling ling
示例3
输入:
-13215
输出:
fu yi san er yi wu
C(clang11) 解法, 执行用时: 1ms, 内存消耗: 376K, 提交时间: 2020-12-18 20:33:38
#include<stdio.h> #include<math.h> int main() {char x; while(scanf("%c",&x)!=EOF) { if(x=='-') {printf("fu"); } if(x=='0') {printf("ling");} if(x=='1') {printf("yi");} if(x=='2') {printf("er"); } if(x=='3') {printf("san"); } if(x=='4') {printf("si"); } if(x=='5') {printf("wu"); } if(x=='6') {printf("liu"); } if(x=='7') {printf("qi"); } if(x=='8') {printf("ba"); } if(x=='9') {printf("jiu"); } printf(" ");}return 0; }
C++ 解法, 执行用时: 3ms, 内存消耗: 480K, 提交时间: 2021-12-05 18:50:55
#include<bits/stdc++.h> using namespace std; int main() { string arr[10] = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu" }; char c; while (cin >> c) { if(c=='-') { cout<<"fu "; continue; } cout << arr[c - '0'] << " "; } return 0; }
Python3(3.9) 解法, 执行用时: 21ms, 内存消耗: 2820K, 提交时间: 2020-12-17 21:28:20
c={"0": "ling","1":"yi","2":"er","3":"san","4":"si","5":"wu","6":"liu","7": "qi","8": "ba","9": "jiu","-":"fu"} d=input() for i in d: print(c[i],end=" ")