1002. Write this number (20) (zjupat)

Source: Internet
Author: User

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)

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.