zoukankan      html  css  js  c++  java
  • PAT-乙级-1002. 写出这个数 (20)

    1002. 写出这个数 (20)

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    8000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。

    输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100

    输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 空格,但一行中最后一个拼音数字后没有空格。

    输入样例:
    1234567890987654321123456789
    
    输出样例:
    yi san wu
    思路:把每个数相加然后再把那个数分开输出拼音
     1 #include<cstdio>
     2 #include<iostream>
     3 #include<string>
     4 using namespace std;
     5 
     6 char a[10][10]= {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
     7 int main()
     8 {
     9     string b;
    10     int i,j,s=0;
    11     cin>>b;
    12     int len=b.length();
    13     for(i=0; i<len; i++)
    14         s+=b[i]-'0';
    15     int t[1000];
    16     int k = 0;
    17     while (s)
    18     {
    19         t[k++] = s % 10;
    20         s/= 10;
    21     }
    22     for(j=k-1; j>=0; j--)
    23     {
    24         if(j==k-1)
    25             cout<<a[t[j]];
    26         else
    27             cout<<" "<<a[t[j]];
    28     }
    29     cout<<endl;
    30     return 0;
    31 }
    我会一直在
  • 相关阅读:
    LeetCode "Jump Game"
    LeetCode "Pow(x,n)"
    LeetCode "Reverse Linked List II"
    LeetCode "Unique Binary Search Trees II"
    LeetCode "Combination Sum II"
    LeetCode "Divide Two Integers"
    LeetCode "First Missing Positive"
    LeetCode "Clone Graph"
    LeetCode "Decode Ways"
    LeetCode "Combinations"
  • 原文地址:https://www.cnblogs.com/zhien-aa/p/5660164.html
Copyright © 2011-2022 走看看