目前定位甲级20分到25分,水~~~~,但是我相信努力可以改变我自己,加油!
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
Accepted 代码:
注意点:(就是数值比较大,可以用字符串输入操作,还有就是sum为零的时候单独判断,PAT有一个特点,,,,反正就是注意0这个数!!!吗,剩下的一个栈就可以解决了。)
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
char n[105];
stack<int>st;
scanf("%s",n);
int sum = 0;
for(int i=0;i<strlen(n);i++)
{
sum+=n[i]-'0';
}
if(sum==0)
{
printf("zero\n");
return 0;
}
while(sum)
{
st.push(sum%10);
sum = sum / 10;
}
while(!st.empty())
{
switch(st.top())
{
case 1:
printf("one");
break;
case 2:
printf("two");
break;
case 3:
printf("three");
break;
case 4:
printf("four");
break;
case 5:
printf("five");
break;
case 6:
printf("six");
break;
case 7:
printf("seven");
break;
case 8:
printf("eight");
break;
case 9:
printf("nine");
break;
case 0:
printf("zero");
break;
}
st.pop();
if(st.empty())
printf("\n");
else printf(" ");
}
return 0;
}