zoukankan      html  css  js  c++  java
  • PAT 1005 Spell It Right

    1005. Spell It Right (20)

    时间限制
    400 ms
    内存限制
    65536 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.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <algorithm>
    #include <math.h>
    #include <queue>
    #include <map>
    #include <strstream>
    #include <string>
    
    using namespace std;
    char a[105];
    map<int,string> m;
    int main()
    {
      m[0]="zero";
      m[1]="one";
      m[2]="two";
      m[3]="three";
      m[4]="four";
      m[5]="five";
      m[6]="six";
      m[7]="seven";
      m[8]="eight";
      m[9]="nine";
      scanf("%s",a);
      int num=0;
      int len=strlen(a);
      for(int i=0;i<len;i++)
        num+=(a[i]-'0');
      string s;
      strstream ss;
      ss << num;
      ss >> s;
      int len2=s.length();
      for(int i=0;i<len2;i++)
      {
        if(i==len2-1)
          cout<<m[s[i]-'0']<<endl;
        else
            cout<<m[s[i]-'0']<<" ";
      }
      return 0;
    
    }


  • 相关阅读:
    产品经理的十宗罪,你犯了几宗?
    产品经理的10大顾虑
    【FastAPI 学习 七】GET和POST请求参数接收以及验证
    【FastAPI 学习 六】异常处理
    【FastAPI 学习 五】统一响应json数据格式
    前端展示(三)
    前端展示(二)
    前端设计(一)
    后端流程分析
    生成词云图
  • 原文地址:https://www.cnblogs.com/dacc123/p/8228624.html
Copyright © 2011-2022 走看看