#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. iis post 请求.html文件报405

    其实本地文件默认是不允许post请求的,但是需要配置一下,配置如下: 我的iis版本是8.5             当然默认也是不能post请求  *.html或是*.json的的文件的,这个问题困 ...

  2. REST内容协商注解

    @Produces注解: 用于定义方法的响应实体的数据类型.可以定义一个或多个,同时可以为每种类型定义质量因素,质量因素取值范围从0--1的小数值,默认为1. 示例: @Path("conn ...

  3. 算法练习之:Biorhythms

    Biorhythms Time Limit: 1000MS Memory Limit: 10000KB  Problem Description Some people believe that th ...

  4. 值得推荐的C/C++框架和库 very good

    [本文系外部转贴,原文地址:http://coolshell.info/c/c++/2014/12/13/c-open-project.htm]留作存档 下次造轮子前先看看现有的轮子吧 值得学习的C语 ...

  5. php Laravel 框架 介绍及安装

    Laravel是一套简洁.优雅的PHP Web开发框架(PHP Web Framework).它可以让你从面条一样杂乱的代码中解脱出来:它可以帮你构建一个完美的网络APP,而且每行代码都可以简洁.富于 ...

  6. 2.6.2 Notification的功能与用法

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...

  7. android-86-Can't create handler inside thread that has not called Looper.prepare()

    以下是Android API中的一个典型的Looper thread实现: //Handler不带参数的默认构造函数:new Handler(),实际上是通过Looper.myLooper()来获取当 ...

  8. VS代码文件中添加协议格式

    //数据帧格式如下 //+-------+-------+-------+-------+---------+------+-------+ //|包头(2)|地址(1)|功能(1)|长度(1)|数据 ...

  9. HDU 5935 Car 【模拟】 (2016年中国大学生程序设计竞赛(杭州))

    Car Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  10. [转]IIS上部署网站

    如何在IIS6,7中部署ASP.NET网站 阅读目录 开始 查看web.config文件 在IIS中创建网站 IIS6 添加扩展名映射 IIS6 无扩展名的映射 目录的写入权限 SQL SERVER的 ...