PAT1005.Spell It Right

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思路:一定要注意数值的取值范围,10^100可能不是longlong 就能解决的问题

 1 #include<cstdio>
 2 #include<cstring>
 3 char data[11][10]=
 4 {
 5     "zero",
 6     "one",
 7     "two",
 8     "three",
 9     "four",
10     "five",
11     "six",
12     "seven",
13     "eight",
14     "nine"
15 };
16 char str[200];
17 int main(int argc, char *argv[])
18 {
19     scanf("%s",str);
20     int sum=0;
21     for(int i=0;str[i]!=‘\0‘;i++)
22     {
23         sum+=str[i]-‘0‘;
24     }
25     sprintf(str,"%d",sum);
26     for(int i=0;i<strlen(str);i++)
27     {
28         int index=str[i]-‘0‘;
29         if(i==strlen(str)-1)
30             printf("%s\n",data[index]);
31         else
32             printf("%s ",data[index]);
33     }
34     return 0;
35 }

时间: 2024-10-04 07:31:52

PAT1005.Spell It Right的相关文章

POJ 1035 Spell checker

题目链接 http://poj.org/problem?id=1035 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24142   Accepted: 8794 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the cor

POJ1035 Spell checker

在做用户查找时 因为要把查找的结果动态加载和显示,所以,那些html元素要由Ajax动态生成.用户打开查找界面时,有系统推荐的用户,而当用户按条件查找后,查找的结果动态加载和显示.所以考虑到用js来搞. 这个for循环就是移除已有的表单.然后根据Ajax请求过来的数据,动态生成新的表单对象.一定要注意j变量从大往小循环,否则,删除div元素后会引起serchResultLenth=serchResult.children.length;长度的变化(这个问题摸索了好久,才搞定,切记) for(va

【ZOJ】3380 Patchouli&#39;s Spell Cards

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3957 题意:m个位置,每个位置填1~n的数,求至少有L个位置的数一样的概率(1<=n,m,l<=100) #include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct inum { static const int N=205,

[ACM] POJ 1035 Spell checker (单词查找,删除替换增加任何一个字母)

Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18693   Accepted: 6844 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given word

ZOJ3380- Patchouli&#39;s Spell Cards(概率DP+计数)

Patchouli's Spell Cards Time Limit: 7 Seconds      Memory Limit: 65536 KB Patchouli Knowledge, the unmoving great library, is a magician who has settled down in the Scarlet Devil Mansion (紅魔館). Her specialty is elemental magic employing the seven ele

1005. Spell It Right (20) -PAT

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: E

git-gui:使用终端打开以后出现错误提示 Spell checking is unavable

参考链接:http://www.lai18.com/content/10706682.html 安装了git-gui,打开以后出现以下提示: Spell checking is unavable: error:No word lists can be found for the language "zh_CN" 原因:打开的时候会进行拼写检查. 解决方法: gedit ~/.gitconfig,然后在文件末尾追加以下内容: [gui] spellingdictionary = none

【概率DP】 ZOJ 3380 Patchouli&#39;s Spell Cards

通道 题意:有m个位置,每个位置填入一个数,数的范围是1~n,问至少有L个位置的数一样的概率 思路: 总数是n^m,我们求没有L个位置一样的数的概率 * 设 dp[i][j]表示用前i个数,填充j个位置的方案数(要符合没有L个位置是一样的数) * dp[i][j]=dp[i-1][j]+Sigm( dp[i-1][j-k]*C[m-(j-k)][k] ) k<=j&&k<L * 其实就是看第i个数,可以不填,填一个位置,两个位置······这样累加过来. * 那么最后的答案就是

PAT 1005. Spell It Right (20)

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 w