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甲級-1015. Reversible Primes (20)
- PAT 甲級 1152 Google Recruitment (20分)GoUI
- 20年春季甲級pat考試
- 【PAT甲級A1084】Broken Keyboard (20分)(c++)C++
- PAT甲級1032 Sharing
- PAT甲級-1140. Look-and-say Sequence (20)(模擬)
- PAT甲級1030 Travel Plan
- 浙大PAT甲級考試
- PAT甲級1023 Have Fun with Number
- 【PAT甲級A1065】A+B and C (64bit) (20分)(c++)C++
- PAT(甲級)2020年秋季考試 7-1 Panda and PP Milk (20分)
- PAT甲級1126~1130|C++實現C++
- PAT甲級-1014. Waiting in Line (30)(模擬)AI
- PAT甲級真題1069 數字黑洞(巧妙解法)
- PAT甲級考試題庫題目分類
- 【PAT甲級A1038】Recover the Smallest Number (30分)(c++)C++
- PAT甲級1122 Hamiltonian Cycle (25分)|C++實現C++
- PAT甲級1154 Vertex Coloring (25分)|C++實現C++
- 2024 秋季PAT認證甲級(題解A1-A4)
- PAT甲級1110 Complete Binary Tree (25分)|C++實現C++
- 2021.9.12週六PAT甲級考試覆盤與總結
- 19年春季第二題 PAT甲級 1157 Anniversary(25 分)
- 菜鳥記錄:c語言實現PAT甲級1010--RadixC語言
- 2020年7月第2題 PAT甲級真題 The Judger (25分)
- (非原創)PAT甲級1123 Is It a Complete AVL Tree (30分)|C++實現C++
- PAT 乙級 1094 谷歌的招聘 (20分)---【素數 字串】谷歌字串
- 【PAT乙級、C++】1024 科學計數法 (20分)C++
- PAT 乙級
- 【PTA甲級、C++簡單解答】1001 A+B Format (20分)C++ORM
- PTA甲級——Be Unique
- PAT 1011 World Cup Betting (20分) 比較大小難度級別
- 2019年9月8日秋季PAT甲級題解-2-1161-Merging Linked Lists (25 分)
- PAT乙級1023
- PAT乙級1004 成績排名 (20分)(C語言版)及解析C語言
- 1021 Deepest Root(甲級)
- PAT:1001 A+B Format (20分)ORM
- 【PAT乙級】1027 列印沙漏
- 【PAT乙級】1017 A除以B
- PAT - 7-20 列印九九口訣表