zoukankan      html  css  js  c++  java
  • 1005 Spell It Right (20)

    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 (<= 10^100^).

    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的情况
     1 #include<iostream>
     2 #include<string>
     3 #include<vector>
     4 using namespace std;
     5 int main(){
     6   string s;
     7   cin>>s;
     8   int l=s.size(), i=0, sum=0;
     9   for(i=0; i<l; i++) sum += (s[i]-'0');
    10   vector<int> v;
    11   while(sum){
    12     v.push_back(sum%10);
    13     sum/=10;
    14   }
    15   if(v.size()==0) cout<<"zero"<<endl;
    16   string num[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
    17   for(i=v.size()-1; i>=0; i--) {
    18     if(i==v.size()-1) printf("%s", num[v[i]].c_str());
    19     else printf(" %s",num[v[i]].c_str());
    20   }
    21   return 0;
    22 }
    有疑惑或者更好的解决方法的朋友,可以联系我,大家一起探讨。qq:1546431565
  • 相关阅读:
    python 基础知识点整理 和详细应用
    DrawText的使用
    虚拟机无法联网解决方法
    Android中ExpandableListView控件基本使用
    PageRank算法
    怎样绕过工信部备案系统
    ASSERT函数
    一键安装 gitlab7 on rhel6.4 并设置邮件发送
    Android Bundle类
    ORACLE EXP命令
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9178300.html
Copyright © 2011-2022 走看看