PAT---1005. Spell It Right (20)
#include<iostream>
#include<stack>
#include<string.h> char *g_WordTable[]= {"zero", "one", "two", "three", "four", "five","six", "seven", "eight", "nine"}; int main()
{
//存放用户输入的数据
char input[];
//当用户输入的数据没有停止的时候
while(scanf("%s", &input) != EOF)
{
int sum = ;
//得到用户输入数据的长度,用到了string.h
int len = strlen(input);
//把每个字符转化为ASCII码,数字字符的ASCII码和数字本身是相等的,求和
for(int i = ; i < len; ++i)
sum += (input[i]-'');
//定义一个栈
std::stack<int> s;
//拆位,个位先放入栈,然后是十百千位
do
{
int temp = sum%;
s.push(temp);
sum /= ;
}while(sum != );
//输出,empty判断堆栈是否为空
while(!s.empty())
{ //得到堆栈栈顶数据
int t = s.top();
//size返回当前堆栈长度(即内部数据个数)
//如果栈的大小事大于1的
if((int)s.size() > )
printf("%s ", g_WordTable[t]);
else
printf("%s\n", g_WordTable[t]);
//pop弹出栈顶的元素
s.pop();
}
}
return ;
}
总结:1.掌握指针数组定义字符串和二维数组定义字符串,指针数组更优
2.掌握拆项的方法
3.掌握栈的方法
PAT---1005. Spell It Right (20)的更多相关文章
- PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642
PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...
- PAT 甲级 1005 Spell It Right (20)(代码)
1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...
- PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏
1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PTA 1005 Spell It Right (20)(20 分)水题
1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...
- 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 ...
- PAT 1005 Spell It Right
1005 Spell It Right (20 分) Given a non-negative integer N, your task is to compute the sum of all ...
- PAT 甲级 1005. Spell It Right (20) 【字符串】
题目链接 https://www.patest.cn/contests/pat-a-practise/1005 思路 因为 n <= 10^100 所以 要用字符串读入 但是 100 * 100 ...
- PAT (Advanced Level) 1005. Spell It Right (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲题题解-1005. Spell It Right (20)-数位求和,水
把每个位上的数字求和sum,然后以英文单词的形式输出sum的每个位 #include <iostream> #include <cstdio> #include <alg ...
- PAT Advanced 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 ...
随机推荐
- C语言头文件书写
说一下C语言的存储类说明符: 1.Auto 只在块内变量声明中被允许,表示变量具有本地生存期. 2.Extern 出现在顶层或块的外部变量函数与变量声明中,表示声明的对象具有静态生存 ...
- C语言程序设计做题笔记之C语言基础知识(下)
C 语言是一种功能强大.简洁的计算机语言,通过它可以编写程序,指挥计算机完成指定的任务.我们可以利用C语言创建程序(即一组指令),并让计算机依指令行 事.并且C是相当灵活的,用于执行计算机程序能完成的 ...
- 蓝牙音箱bose soundlink mini2链接mac后itunes自动启动的问题解决
1.在应用程序列表中复制一个应用重命名为DoNothingApp.app(非系统应用才可以成功复制) 2.打开terminal执行该命令(执行后需要输入密码),注意mv和iTunes.app后分别有一 ...
- Linux find命令详解
转自Linux find命令详解 一.find 命令格式 1.find命令的一般形式为: find pathname -options [-print -exec -ok ...] 2.find命令的 ...
- 李洪强iOS开发-网络新闻获取数据思路回顾
李洪强iOS开发-网络新闻获取数据思路回顾 01 创建一个继承自AFHTTPSessionManager的工具类:LHQNetworkTool 用来发送网络请求获取数据 1.1 定义类方法返回单例对 ...
- VC下载文件显示进度条
VC下载文件显示进度条 逗比汪星人2009-09-18上传 by Koma http://blog.csd.net/wangningyu http://download.csdn.net/deta ...
- Android 获取图片资源的4种方式
1. 图片放在sdcard中 Bitmap imageBitmap = BitmapFactory.decodeFile(path) (path 是图片的路径,跟目录是/sdcard) 2. 图片在项 ...
- C++类的大小
C++类的大小 一个空类class A{};的大小为什么是1,因为如果不是1,当定义这个类的对象数组时候A objects[5]; objects[0]和objects[1]就在同一个地址处,就无 ...
- Python urllib2写爬虫时候每次request open以后一定要关闭
最近用python urllib2写一个爬虫工具,碰到运行一会程序后就会出现scoket connection peer reset错误.经过多次试验发现原来是在每次request open以后没有及 ...
- Is the Information Reliable?(差分约束)
Description The galaxy war between the Empire Draco and the Commonwealth of Zibu broke out 3 years a ...