PAT 07-0 write this number, written by the pat07-0

Source: Internet
Author: User

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 ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.