#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. SQL Server 2008 R2 主从数据库同步设置

    一.准备工作: 主数据库服务器: OS:Windows Server 2008 R2    DB: SQL Server 2008 R2 Hostname : CXMasterDB IP: 192.1 ...

  2. 让IIS识别PUT和DELETE请求

    转眼间年底了,突然的我就挪了窝.新的公司,新的电脑,新的服务器....面对新环境,手有些痒,于是试着编写自己的简易版restful API. restful的话,对资源的相应操作应该被体现成http动 ...

  3. 定位 - MapKit - 基本使用

    /** *  Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Co ...

  4. Http协议Get方式获取图片

    一.                二.                         我试了试,Post方式也行啊,干嘛要叫强调Get方式,费解~~       答曰:get是向服务器请求数据,p ...

  5. ember.js

    http://blog.geoinker.com/2012/12/29/seven-javascript/ http://www.csdn.net/article/2013-04-15/2814893 ...

  6. 在openshift上自定义node.js的版本

    https://github.com/ramr/nodejs-custom-version-openshift 由于是线上服务器,一步一步来: 先把上面的工程拉下来,覆盖到初始化的工程里,提交,让服务 ...

  7. BroadCastReceiver中耗时操作导致ANR

    現象:廣播接收器中進行耗時的I/O操作導致ANR. 查資料發現每次广播到来时 , 会重新创建 BroadcastReceiver 对象 , 并且调用 onReceive() 方法 , 执行完以后 该对 ...

  8. 【HDOJ】2721 Persistent Bits

    题目有点长,但是题意说的很清楚.位操作. #include <stdio.h> ]; int main() { int a, b, c, s; int i, j, k, n, tmp, m ...

  9. 【HDOJ】1239 Calling Extraterrestrial Intelligence Again

    这题wa了很多词,题目本身很简单,把a/b搞反了,半天才检查出来. #include <stdio.h> #include <string.h> #include <ma ...

  10. c++ lambda返回类型自动推导的一些需要注意的地方

    一句话,lambda返回类型自动推导走的是auto,而不是decltype,注意. class ObjectA { public: ObjectA() { val_ = ++g; } ObjectA( ...