#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. Web负载均衡的几种方式

    Web负载均衡的几种实现方式 摘要:负载均衡(Load Balance)是集群技术(Cluster)的一种应用.负载均衡可以将工作任务分摊到多个处理单元,从而提高并发处理能力.目前最常见的负载均衡应用 ...

  2. jquery.inputmask.js 输入框input输入内容格式限制插件

    今天使用的就是这几行代码. 利用 jquery.inputmask.js  下载地址(如果打不开的话 请FQ http://plugins.jquery.com/jquery.inputmask/) ...

  3. ySQL for mac使用记录

    一.登录 打开终端,输入/usr/local/mysql/bin/mysql -u root -p 初次进入mysql,密码为空.当出现mysql>提示符时,表示你已经进入mysql中.键入ex ...

  4. Longest common prefix | leetcode

    Write a function to find the longest common prefix string amongst an array of strings. 思路:要去是寻找字符串ve ...

  5. PHP中的urlencode和urldecode的理解

    平时在工作中经常要写 $xxx = urldecode($_GET['xxx']);的类似代码,大部分的情况都是没有问题的.也能很好的工作. 所以也没有怎么在意.但是突然有一天我想到 $xxx =$_ ...

  6. C语言程序设计做题笔记之C语言基础知识(上)

    C语言是一种功能强大.简洁的计算机语言,通过它可以编写程序,指挥计算机完成指定的任务.我们可以利用C语言创建程序(即一组指令),并让计算机依指令行事.并且C是相当灵活的,用于执行计算机程序能完成的几乎 ...

  7. 思考 Swift 中的 MirrorType 协议

    Swift中的反射非常有限,仅允许以只读方式访问元数据的类型子集.或许 Swift 因有严格的类型检验而不需要反射.编译时已知各种类型,便不再需要进行进一步检查或区分.然后大量的 Cocoa API ...

  8. Being a Hero

    zoj3241:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3241 题意:一个国家的地图是一张n个点m条边的有向图.你保 ...

  9. Android用户界面 UI组件--TextView及其子类(一) TextView

    1.TextView android:autoLink设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none /web/email/phone/map/a ...

  10. css全局设置

      /***** 全局设置 *****/ body,h1,h2,h3,h4,h5,h6,p,form,ul,ol,li,dt,dl,dd,th,td,label,bottom,input,textar ...