Task
Convert number to Chinese Pinyin. Minus sign is equal to “fu”.
key-value
# num: pinyin
<code>0: ling
1: yi
2: er
3: san
4: si
5: wu
6: liu
7: qi
8: ba
9: jiu
</code>
<code>0: ling
1: yi
2: er
3: san
4: si
5: wu
6: liu
7: qi
8: ba
9: jiu
</code>
0: ling
1: yi
2: er
3: san
4: si
5: wu
6: liu
7: qi
8: ba
9: jiu
Code
<code>#include <stdio.h>
int main() {
char ipt[100];
char py[10][6] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
fgets(ipt, 100, stdin);
int i = 0;
if (ipt[0] == '-') {
printf("%s ", "fu");
i++;
}
for (i; i < strlen(ipt); i++) {
if (i < strlen(ipt) - 1)
printf("%s ", py[ipt[i] - '0']);
else
printf("%s", py[ipt[i] - '0']);
}
return 0;
}
</code>
<code>#include <stdio.h>
int main() {
char ipt[100];
char py[10][6] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
fgets(ipt, 100, stdin);
int i = 0;
if (ipt[0] == '-') {
printf("%s ", "fu");
i++;
}
for (i; i < strlen(ipt); i++) {
if (i < strlen(ipt) - 1)
printf("%s ", py[ipt[i] - '0']);
else
printf("%s", py[ipt[i] - '0']);
}
return 0;
}
</code>
#include <stdio.h>
int main() {
char ipt[100];
char py[10][6] = {"ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"};
fgets(ipt, 100, stdin);
int i = 0;
if (ipt[0] == '-') {
printf("%s ", "fu");
i++;
}
for (i; i < strlen(ipt); i++) {
if (i < strlen(ipt) - 1)
printf("%s ", py[ipt[i] - '0']);
else
printf("%s", py[ipt[i] - '0']);
}
return 0;
}
Tested case
I inputed 600, the output is “liu ling ling”. I have tested some other numbers, and all of them seems good, but the checking website said I was wrong.
New contributor
mamaruo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.