zoukankan      html  css  js  c++  java
  • PAT甲1005 Spell it right【字符串】

    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(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

    题意:

    给一个最多100位的数字,把各位上的数求和,把结果各位上的数字翻译成英文输出。

    思路:

    暴力。

     1 #include <iostream>
     2 #include <set>
     3 #include <cmath>
     4 #include <stdio.h>
     5 #include <cstring>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <queue>
     9 #include <map>
    10 using namespace std;
    11 typedef long long LL;
    12 #define inf 0x7f7f7f7f
    13 
    14 char s[105];
    15 string spell[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    16 int str[105];
    17 
    18 int main()
    19 {
    20     scanf("%s", s);
    21     int n = strlen(s);
    22     int ans = 0;
    23     for(int i = 0; i < n; i++){
    24         ans += s[i] - '0';
    25     }
    26     int l = 0;
    27     if(ans == 0){
    28         str[l++] = 0;
    29     }
    30     while(ans){
    31         str[l++] = ans % 10;
    32         ans /= 10;
    33     }
    34 
    35     cout<<spell[str[l - 1]];
    36     for(int i = l - 2; i >= 0; i--){
    37         cout<<" "<<spell[str[i]];
    38     }
    39     cout<<endl;
    40 
    41     return 0;
    42 }
  • 相关阅读:
    Mac eclipse导入项目中文乱码问题解决
    初识Freemarker
    Mac 导入maven项目详解
    Mac iTerm2使用总结
    HTML学习笔记——标签
    仿QQ大战—界面篇
    Java之类的构造器(反射)
    JAVA之IO流(字符流)
    JAVA之IO流(字节流)
    仿QQ大战—服务器的搭建(ServerSocket)
  • 原文地址:https://www.cnblogs.com/wyboooo/p/9866795.html
Copyright © 2011-2022 走看看