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
  • 相关阅读:
    搭建Jumpserver
    支付功能流程图
    我是如何招聘程序员的
    从问题域看hadoop的各种技术
    转一篇做BI项目的好文
    关于数据倾斜的问题
    技能的十一个级别
    企业计划体系的变迁:从ERP到APS再到SCP
    别浪费自己的高学历
    一个CTO谈自己的技术架构体系
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9178300.html
Copyright © 2011-2022 走看看