1005 Spell It Right (20 分)——13行代码Ac
生活随笔
收集整理的這篇文章主要介紹了
1005 Spell It Right (20 分)——13行代码Ac
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
立志用最少的代碼做最高效的表達
PAT甲級最優題解——>傳送門
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)N (≤10^100)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<bits/stdc++.h> using namespace std; string ss[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; int main() {string s; getline(cin, s);int sum = 0;for(auto i : s) sum += i-'0';s = to_string(sum);for(int i = 0; i < s.size(); i++) {if(i != 0) putchar(' ');cout << ss[s[i]-'0'];} return 0; }
總結
以上是生活随笔為你收集整理的1005 Spell It Right (20 分)——13行代码Ac的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【两种解法】1004 Counting
- 下一篇: 【测试点5】1007 Maximum S