目录

题目:

解题思路:

C语言实现:


题目:

1005 Spell It Right (20)(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 which contains an N (<= 10^100^).

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

解题思路:

大数存储计算与字符转换问题。用栈的方式保存数值,打印对应值结果。

C语言实现:

#include<stdio.h>int main(int argc, char** argv) {char numOfEnglish[10][6]={"zero","one","two","three","four","five","six","seven","eight","nine"};int num[101]={0}; //计算数组 int count=0;        //栈顶 int i;char temp=NULL;while((temp=getchar())!='\n'){num[0]+=temp-'0';i=0;while(num[i]>=10){       //当前位置大于10则进位 num[i+1]+=num[i]/10;num[i]%=10;++i;if(i>count)count=i;}}for(int j=count;j>=0;--j){printf("%s",numOfEnglish[num[j]]);if(j>0){printf(" ");}}return 0;
}

1005 Spell It Right (20)相关推荐

  1. 【PAT (Advanced Level) Practice】1005 Spell It Right (20 分)

    #include<iostream> #include<cstdio> #include<cstdlib> #include<string> #incl ...

  2. 【PAT甲级 StringBuilder的使用】1005 Spell It Right (20 分) Java版 7/7通过

    题目 挺简单的,是个水题 坑 & 心得 一开始switch (i)忘了写case 0的情况,导致两个测试点没通过,不过很快就发现了 int 类型的 sum 转换为 str 的方式:用空字符串拼 ...

  3. PAT甲级 -- 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 e ...

  4. 1005 Spell It Right (20 分)——13行代码Ac

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given a non-negative integer N, your task is to compute the sum o ...

  5. 【PAT】1005 Spell It Right (20 分)——字符串处理

    //要么处理字符串,要么就数字分解,都想到了没有有效组合 //我的解法1:加法结果还是int,最后逆序分解数字,按序插入#include <iostream> #include <s ...

  6. 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 al ...

  7. PAT甲级1005 Spell It Right :[C++题解]字符串处理

    文章目录 题目分析 题目链接 题目分析 ac代码 #include<bits/stdc++.h> using namespace std;const int N =110;string n ...

  8. 【PAT - 甲级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 outp ...

  9. 1005 Spell It Right

    基本步骤是:100位的数字longlong也存不下,作为字符串读入,对字符串进行遍历,每个字符减去'0'加到总和sum上,再将整形的总和sum转化为字符串,对得到的字符串进行遍历,将每个字符映射到英文 ...

  10. PAT甲级题目翻译+答案 AcWing(字符串处理)

    1001 A+B Format (20 分) 题意 :将整数转换成标准格式 思路 :从后往前遍历字符串进行模拟,每三个数字加一个逗号,但不能是在最前面加逗号,也不能是加在负号后面 #include & ...

最新文章

  1. 系统启动过程Linux
  2. 软件包管理 之 Fedora Extras(Fedora 计划的扩充资源) rpm.livna.org软件仓库的介绍和应用...
  3. 直播预告 | 全国大学生智能汽车竞赛全向行进组——基础培训
  4. sae mysql django_Python+Django+SAE系列教程12-----配置MySQL数据库
  5. dnf超时空漩涡副本路线流程图_DNF:超时空漩涡开荒全攻略一览,你顺利通关了么?...
  6. 一文讲透 Git 底层数据结构和原理
  7. 当我们在谈 .NET Core 跨平台时,我们在谈些什么?--学习笔记
  8. 20个天才般的走心设计,真是太牛了!
  9. 用python批量下载网络图片_python 批量下载网页里的图片
  10. 信数金服:决策模型的迭代
  11. NoSQL Redis的学习笔记
  12. Android ContentProvider简单总结
  13. 抖音品质建设 - iOS启动优化《原理篇》
  14. MSSQL·手动安装机器学习相关CAB文件
  15. IDEA删除多余空行
  16. 在线学习Java的资源网站
  17. java程序员要学什么?
  18. 分享一个优雅的vi配置
  19. 在WSL上编译并运行全志XR806的完全体demo
  20. Linux:安装和配置tomcat详细教程

热门文章

  1. 事务Transaction的理解(一)
  2. DVWA-SQL Injection
  3. Ubuntu Temporary failure in name resolution 问题
  4. python表格数据对比_python入门之对比两份excel表格数据
  5. 硕士期间两篇计算机sci二区,我院青年教师陈新华今年连续两篇论文在中科院二区SCI期刊见刊...
  6. 太强了,这款开源终端工具可查询 IP 信息 ...
  7. 关于数据分析岗位的工作思考
  8. 解剖热敏打印原理—热敏打印机真的没墨水了吗?
  9. python适合创业吗-python创业
  10. 穿越技术火线,聆听内心声音——暨龙泉第三届IT禅修营