PAT 07-0 write this number, written by the pat07-0
Output the sum of the numbers in pinyin. This may be more appropriate than the above title. Here I used sprintf () (stdio. h) This function, I was looking for itoa () (stdlib. h) The function is used. Check the information and check that this function is not an ANSI standard function and can be replaced by sprintf (). In addition, this function is very powerful, it is not used here. mark it. The following describes the question design requirements and code implementation.
/* Name: Copyright: Author: Date: 01/04/15 Description: reads a natural number n, calculates the sum of all its digits, and writes each digit of the sum 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 sample: 1234567890987654321123456789 output sample: yi san wu */# include <stdio. h> # include <string. h> int main () {// freopen ("in.txt", "r", stdin); // for test char * num [] = {"ling ", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu"}; char ch, s [3], * p; int sum, l; p = s; sum = 0; while (ch = getchar () & ch! = '\ N') sum + = ch-'0'; sprintf (p, "% d", sum); l = strlen (s); int I; for (I = 0; I <l; I ++) {printf ("% s", num [s [I]-'0']); if (I! = L-1) printf (""); else printf ("\ n") ;}// fclose (stdin); // for test return 0 ;}