PAT甲級-1005. Spell It Right (20)各位之和
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:12345Sample Output:
one five
計算給出的數字的各個位上的數之和,並用英文形式輸出。
#include<bits/stdc++.h>
using namespace std;
#define INF 0xfffffff
#define MAXN 1010
string change(char x)
{
if(x=='0') return "zero";
else if(x=='1') return "one";
else if(x=='2') return "two";
else if(x=='3') return "three";
else if(x=='4') return "four";
else if(x=='5') return "five";
else if(x=='6') return "six";
else if(x=='7') return "seven";
else if(x=='8') return "eight";
return "nine";
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("F:/cb/read.txt","r",stdin);
//freopen("F:/cb/out.txt","w",stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin>>s;
long long len=s.length();
long long ans=0;
for(int i=0; i<len; ++i)
ans+=(s[i]-'0');//各位之和
string ss="";
if(ans==0) ss+="0";
while(ans>0)
{
ss+=(char(ans%10+'0'));//各位之和轉成字串
ans/=10;
}
reverse(ss.begin(),ss.end());//翻轉字串
len=ss.length();
for(int i=0; i<len-1; ++i)
cout<<change(ss[i])<<" ";
cout<<change(ss[len-1])<<endl;
return 0;
}
相關文章
- PAT 甲級 1152 Google Recruitment (20分)GoUI
- PAT甲級1023 Have Fun with Number
- 【PAT甲級A1084】Broken Keyboard (20分)(c++)C++
- 2024 秋季PAT認證甲級(題解A1-A4)
- PAT甲級考試題庫題目分類
- 【PAT甲級A1038】Recover the Smallest Number (30分)(c++)C++
- 2021.9.12週六PAT甲級考試覆盤與總結
- 【PAT甲級A1065】A+B and C (64bit) (20分)(c++)C++
- PAT甲級1126~1130|C++實現C++
- PAT甲級-1010. Radix (25)進位制
- PAT甲級-1012. The Best Rank (25)並列排序排序
- PAT甲級1154 Vertex Coloring (25分)|C++實現C++
- PAT甲級1122 Hamiltonian Cycle (25分)|C++實現C++
- PAT甲級-1014. Waiting in Line (30)(模擬)AI
- PAT甲級1110 Complete Binary Tree (25分)|C++實現C++
- (非原創)PAT甲級1123 Is It a Complete AVL Tree (30分)|C++實現C++
- 菜鳥記錄:c語言實現PAT甲級1010--RadixC語言
- 【PAT乙級】1048 數字加密加密
- PAT 乙級 1094 谷歌的招聘 (20分)---【素數 字串】谷歌字串
- 【PAT乙級、C++】1024 科學計數法 (20分)C++
- PAT乙級——1093(字串匹配)Java實現字串匹配Java
- PAT乙級比賽-互評成績計算
- PAT乙級1004 成績排名 (20分)(C語言版)及解析C語言
- 【PTA甲級、C++簡單解答】1001 A+B Format (20分)C++ORM
- PTA甲級 1076 Forwards on Weibo (30分)Forward
- 【Lintcode】1485. Holy Grail spellAI
- Python使用遞迴法和函數語言程式設計計算整數各位之和Python遞迴函數程式設計
- 3186. Maximum Total Damage With Spell CastingAST
- PAT 2023 冬 乙 方格填數
- clear:left/right 理解
- PAT乙級——1092(陣列排序 自定義sort)Java實現陣列排序Java
- 2022年冬pat乙級考試題目及程式碼解析附部分錯誤原因
- [PAT]1027. Colors in Mars (20)@Java實現Java
- 2020/10/31·Leetcode·兩數之和LeetCode
- 兩數之和
- 【譯】 Types are moving to the right
- Oracle Left join right jionOracle
- Right here waitingAI