zoukankan      html  css  js  c++  java
  • 浙江大学PAT上机题解析之1005. Spell It Right (20)

    1005. Spell It Right (20)

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

    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 (<= 10100).

    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
    
     
    #include<iostream>
    #include <string>
    #include <stack>
    
    using namespace std;
    
    string  getString(int n)
    {
      switch(n)
      {
      case 0:return "zero";break;
      case 1:return "one";break;
      case 2:return "two";break;
      case 3:return "three";break;
      case 4:return "four";break;
      case 5:return "five";break;
      case 6:return "six";break;
      case 7:return "seven";break;
      case 8:return "eight";break;
      case 9:return "nine";break;
    
      }
    }
    
    
    int main()
    {
      string   str;       
      string::iterator it;
      int flag=false;
      stack<int>   s;
      int sum=0;
      cin>>str;
      for (it=str.begin();it!=str.end();it++)
        sum += (*it)-'0';  
        while(sum)
      {
        s.push(sum%10);
        sum/=10;
      }
      if (s.empty())
          cout<<"zero";
    
      while(!s.empty())
      {
        if (flag)
        cout<<" ";
        else
        flag = true;
    
         cout<<getString(s.top());
         s.pop();  
      }
      cout<<endl;
     
      //system("pause");
      return 0;
    } 
    
    

  • 相关阅读:
    【ExtJS】关于自定义组件(一)
    【ExtJS】关于自定义组件
    特殊的css样式
    样式表笔记
    html 表单笔记
    图片热点和网页内嵌随笔
    快速网页
    HTML基础和表格
    HTML基础
    递归算法 笔记
  • 原文地址:https://www.cnblogs.com/ainima/p/6331280.html
Copyright © 2011-2022 走看看