1002. 写出这个数 (20)

1002. 写出这个数 (20)

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

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

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

输入样例:
1234567890987654321123456789
输出样例:
yi san wu
#include <iostream> 
#include <stack>
using namespace std;
string pinyin[]={"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
int main(void)
{
  string input;
  cin>>input;
  int i=0;
  int count=0; 
  while(i<input.length())
  {
    
    count+=input[i]-'0';
    i++;
  }
  stack<string> res;
  while(count>0)
  {
    int rear = count%10;
    count /=10;
    res.push(pinyin[rear]);
  }
  while(res.size()>1)
  {
    cout<<res.top()<<" ";
    res.pop();
  }
  cout<<res.top()<<endl;
  return 0;
}
原文地址:https://www.cnblogs.com/xiongmao-cpp/p/6367892.html