首页 > 其他 > 详细

1005 Spell It Right (20 分)

时间:2019-11-23 22:57:16      阅读:77      评论:0      收藏:0      [点我收藏+]

题目链接:

https://pintia.cn/problem-sets/994805342720868352/problems/994805519074574336

题目描述:

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.

Input Specification:

Each input file contains one test case. Each case occupies one line which contains an N (≤).

Output Specification:

For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.

Sample Input:

12345

Sample Output:

one five

题目大意:

给定一个字符串,求各位相加之和,用英文逐字翻译。

思路:

妥妥的水题……就是得注意一下输入0时的情况。

AC代码:

技术分享图片
#include <iostream>
#include<cstdio>
#include<stack>
using namespace std;

char ch1[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};

int main()
{
    char ch;
    int sum = 0;
    while((ch=getchar())!= \n)    //各位加和
    {
        sum= sum+ch - 0;
    }
    stack <int> q;
    if(sum == 0) q.push(0);         //防止输入的为0
    while(sum!=0)                   //反转
    {
        q.push(sum%10);
        sum/=10;
    }
    cout << ch1[q.top()];
    q.pop();
    while(!q.empty())
    {
        cout <<   << ch1[q.top()];
        q.pop();
    }
    return 0;
}
View Code

 

1005 Spell It Right (20 分)

原文:https://www.cnblogs.com/abszse/p/11919845.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!