题目链接

https://www.patest.cn/contests/pat-a-practise/1005

思路

因为 n <= 10^100

所以 要用字符串读入

但是 100 * 100 = 10000

所以 sum 用int 保存就好了

再把 sum 的每一位 用 英文输出

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss; const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-30; const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7; string tran(int x)
{
string s = "";
if (x == 0)
return "0";
while (x)
{
s += x % 10 + '0';
x /= 10;
}
return s;
} int main()
{
string s;
cin >> s;
int len = s.size();
int sum = 0;
for (int i = 0; i < len; i++)
sum += s[i] - '0';
map <char, string> m;
m['0'] = "zero";
m['1'] = "one";
m['2'] = "two";
m['3'] = "three";
m['4'] = "four";
m['5'] = "five";
m['6'] = "six";
m['7'] = "seven";
m['8'] = "eight";
m['9'] = "nine";
string ans = tran(sum);
len = ans.size();
for (int i = len - 1; i >= 0; i--)
{
if (i != len - 1)
printf(" ");
cout << m[ans[i]];
}
cout << endl;
}

PAT 甲级 1005. Spell It Right (20) 【字符串】的更多相关文章

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

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

  3. PAT 甲级 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 th ...

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

  5. Day 006:PAT练习--1005 Spell It Right (20 分)

    上星期一直在写报告乱七八糟的,从今天开始不刷乙级的了,还是多刷甲级进步来得快一点! 显而易见,该题的关键在于将输入之和的每一位从高到低输出,这里我们发现题意中的输入数的范围为0-10^100,显然我们 ...

  6. PAT甲级题解-1100. Mars Numbers (20)-字符串处理

    没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是“hel”,而不是“hel tret”. 代码: #include <iostream> #inc ...

  7. PAT 甲级 1005 Spell It Right

    https://pintia.cn/problem-sets/994805342720868352/problems/994805519074574336 Given a non-negative i ...

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

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

随机推荐

  1. ylb:日期和时间函数

    ylbtech-SQL Server:SQL Server-日期和时间函数 日期和时间函数. ylb:日期和时间函数 返回顶部 1,日期和时间函数获取(当前)日期 GetDate() 2,提取部分日期 ...

  2. 【京东账户】——Mysql/PHP/Ajax爬坑之购物车删除选项

    一.引言 做京东账户项目中的购物车模块,功能之三就是删除购物车中的选项.要用到的是Apach环境,Mysql.PHP以及Ajax. 二.依据功能创建库.表.记录 创建库:jd 创建表:购物车表  jd ...

  3. Mockito图书馆

    转载:https://static.javadoc.io/org.mockito/mockito-core/2.12.0/org/mockito/Mockito.html#42 org.mockito ...

  4. 微信小程序 - 关闭当前页面无法再通过左上角返回

    考试的时候不可能答完以后,得到成绩后再通过左上角返回再重新答吧? 可以通过:open-type='redirectTo'实现

  5. beforeRouteLeave 实现vue路由拦截浏览器的需求,进行一系列操作 草稿保存等等

    场景:为了防止用户失误点错关闭按钮等等,导致没有保存已输入的信息(关键信息).用法://在路由组件中: beforeRouteLeave (to, from, next) { if(用户已经输入信息) ...

  6. 策略模式(headfirst设计模式学习笔记)

    鸭子的行为被封装 进入一组类中,能够轻易的扩展和改变.假设须要能够执行时改变行为! 策略模式定义了算法族.分别封装起来.让他们能够相互替换,此模式让算法的变化独立于使用算法的客户. 继承,相似之处用继 ...

  7. linux下robotframework执行测试用例的几种方法

    1.执行指定的测试用例文件(Test Suite)     [root@localhost cases]# pybot purge.txt   2.执行整个porject目录下的所有测试用例     ...

  8. 为备考二级C语言做的代码练习---辅导资料《C语言经典编程282例》--(1)

    因为二级考试的时候用的C语言编译器是VC++6.0 真是日了狗了 用这个编译器 这是我第2个C编译器吧,第一个用的是啊哈C编译器..第二个是VS++6.0 然后在win下用VS2013感觉挺不错的 毕 ...

  9. DataTable去除空行

    protected void removeEmpty(DataTable dt) { List<DataRow> removelist = new List<DataRow>( ...

  10. 地上有一个m行和n列的方格。一个机器人从坐标0,0的格子开始移动,每一次只能向左,右,上,下四个方向移动一格,但是不能进入行坐标和列坐标的数位之和大于k的格子。 例如,当k为18时,机器人能够进入方格(35,37),因为3+5+3+7 = 18。但是,它不能进入方格(35,38),因为3+5+3+8 = 19。请问该机器人能够达到多少个格子?

    // test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...