1005. Spell It Right (20)
2018-03-01 17:09
344 查看
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我有罪呀,我忘记字符串怎么初始化呀,特别是指针式字符串,例如char *input, 我怎么指定这个字符串大小呀?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *nToW[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
char input[101];
/**< 读入部分 */
gets(input);
int len = strlen(input);
/**< 计算各个位数相加结果 */
int sum = 0;
int i;
for(i=0; i<len; i++)
{
sum += (input[i]-'0');
}
/**< 计算sum最大能被哪个数除还能剩下个位数 */
int divider = 1;
while(1)
{
if(sum/divider<10)
{
break;
}
else
{
divider *= 10;
}
}
/**< 逐个计算商并输出 */
int quotient;
while(divider>0)
{
quotient = sum/divider;
sum %= divider;
printf("%s", nToW[quotient]);
if(divider!=1)
printf(" ");
divider /= 10;
}
system("pause");
}
相关文章推荐
- PAT A 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT(甲级)1005. Spell It Right (20)
- PAT 1005. Spell It Right (20)
- PAT(甲级)1005. Spell It Right (20)
- 1005. Spell It Right (20)
- PAT (Advanced Level) 1005. Spell It Right (20) 解题报告
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005 Spell It Right (20)
- 1005. Spell It Right (20)
- PAT 1005. Spell It Right(20)
- PAT A 1005. Spell It Right (20)
- 1005. Spell It Right (20)
- 1005. Spell It Right (20)(C++)
- PAT---1005. Spell It Right (20)
- 1005. Spell It Right (20)