Link: http://pat.zju.edu.cn/contests/pat-b-practise/1002
Read a natural number N, calculate the sum of all its numbers, and write each digit in Chinese pinyin.
Input Format:Each test input contains one test case, that is, the value of natural number n. N must be less than 10100.
Output Format:Output each digit of N in a row. There is a space between the pinyin numbers, but there is no space after the last pinyin number in a row.
Input example:
1234567890987654321123456789
Output example:
yi san wu
The Code is as follows:
#include <cstdio>#include <cstring>typedef long long LL;const int MAXN = 117;char s[MAXN];char num[10][7] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};int ans[MAXN];LL sum;void Print(){ int l = 0; while(sum > 0) { int tt = sum%10; ans[l++] = tt; sum/=10; // printf("%c\n",ans[l-1]); } for(int i = l-1; i > 0; i--) { printf("%s ",num[ans[i]]); } printf("%s\n",num[ans[0]]);}int main(){ while(gets(s)) { int len = strlen(s); sum = 0; for(int i = 0; i < len; i++) { sum+=s[i]-'0'; } // printf("%I64d\n",sum); Print(); } return 0;}
1002. Write this number (20) (zjupat)