#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)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

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

  7. PAT 甲级 1005. Spell It Right (20) 【字符串】

    题目链接 https://www.patest.cn/contests/pat-a-practise/1005 思路 因为 n <= 10^100 所以 要用字符串读入 但是 100 * 100 ...

  8. PAT (Advanced Level) 1005. Spell It Right (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  9. PAT甲题题解-1005. Spell It Right (20)-数位求和,水

    把每个位上的数字求和sum,然后以英文单词的形式输出sum的每个位 #include <iostream> #include <cstdio> #include <alg ...

  10. 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 ...

随机推荐

  1. gulp解决RequireJS

    gulp解决RequireJS项目前端缓存问题(二)   前言 这一节,我们主要解决在上一节<使用gulp解决RequireJSs项目前端缓存问题(一)>末尾提到的几个问题: 对通过req ...

  2. uva 812 Trade on Verweggistan

    题意: 给w个货架, 每个货架上有bi个货物, 每次只能拿最上面的货物, 每个货物有个价值, 所有货物的售价均为10. 问:能获得的最大利润, 以及能获得这个利润需要多少个货物. (有多种组合时只需输 ...

  3. 打开网页自动弹出qq客户端

    新建js后调用即可,打开网站自动弹出qq对话框,若qq为关闭状态则启动qq,之后弹出对话框. document.write("<iframe src='tencent://messag ...

  4. delphi xe5 android 开发数据访问server端(二)

    上一篇我们创建了一个拟给手机端访问的webservices服务 接下来创建一个返回数据集的过程,用webservices发布,供手机端调用.这里我使用firedac 1.打开上一篇自动创建的WebMo ...

  5. Android 模拟登陆 保存密码(信息)到手机中 文件信息读取

    package com.wuyou.login; import java.io.IOException; import java.util.Map; import android.app.Activi ...

  6. 【Bzoj 3295】 动态逆序对(树套树|CDQ分治)

    [题意] 每次删除一个数,然后问删除前逆序对数. [分析] 没有AC不开心.. 我的树状数组套字母树,应该是爆空间的,空间复杂度O(nlogn^2)啊..哭.. 然后就没有然后了,别人家的树套树是树状 ...

  7. binder

    Service与Android系统设计(7)--- Binder驱动 http://blog.csdn.net/21cnbao/article/details/8087354 Android Bind ...

  8. Qt浅谈之三十九圆形进度条(已经有50篇了)

    http://blog.csdn.net/taiyang1987912/article/category/2314763

  9. -_-#【JS】element.click()

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. 【转】Android:Animation的简单学习--不错

    原文网址:http://blog.csdn.net/huangbiao86/article/details/6683665 Animation动画效果.提供了一系列的动画效果,可以应用大多数 的控件. ...