PAT 甲级 1005. Spell It Right (20) 【字符串】
题目链接
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) 【字符串】的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Day 006:PAT练习--1005 Spell It Right (20 分)
上星期一直在写报告乱七八糟的,从今天开始不刷乙级的了,还是多刷甲级进步来得快一点! 显而易见,该题的关键在于将输入之和的每一位从高到低输出,这里我们发现题意中的输入数的范围为0-10^100,显然我们 ...
- PAT甲级题解-1100. Mars Numbers (20)-字符串处理
没什么好说的,注意字符串的处理,以及当数字是13的倍数时,只需高位叫法的单词.比如26,是“hel”,而不是“hel tret”. 代码: #include <iostream> #inc ...
- PAT 甲级 1005 Spell It Right
https://pintia.cn/problem-sets/994805342720868352/problems/994805519074574336 Given a non-negative i ...
- 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 ...
- 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 ...
随机推荐
- git 指令如何撤销一次merge
在使用git指令时难免会发生错误的merge的情况,那么如何在这种情况下回退到错误发生之前的情况? git reflog 指令显示历史的操作 4457e43 HEAD@{0}: reset: movi ...
- Struts2 convention插件试用+ Spring+Hibernate SSH整合
第一步,引入struts2-convention-plugin-2.2.1.jar 然后,改动配置文件. 我是在struts.properties文件里改动的: struts.objectFactor ...
- 知其一不知其二之Jenkins Hacking
转自安全脉搏 本文首发安全脉搏 感谢大王叫我来巡山 的投递 转载请注明来源 大多安全工作者听到jenkins都会知道有个未授权的命令执行 但是如果Script页面要授权才能访问呢 或者你的用户没有Ov ...
- iframe 实现网页本页显示
<el-dialog title="" :visible.sync="dialogVisible"> <iframe src="ht ...
- 分享一套C++入门基础视频
本课程从C++起步.用户无需不论什么计算机基础,仅仅须要懂的主要的电脑操作,既可学习本课程.本课程适合在校大学生,在职人员等,通过本课程的学习,学员可掌握C++\MFC\VC++server端.网络编 ...
- SAS学习经验总结分享:篇五-过程步的应用
之前已经介绍过BASE SAS分为数据步和过程步,过程步是对数据步生成的数据集进行分析和处理,并挖掘数据信息,写出分析报告做总结评价. (本文为原创,禁止复制或转载,转载务必标明出处:http://w ...
- Linux内核中链表的学习
一.自己学习链表 数组的缺点:(1)数据类型一致:(2)数组的长度事先定好,不能灵活更改. 从而引入了链表来解决数组的这些缺点:(1)结构体解决多数据类型(2)链表的组合使得链表的长度可以灵活设置. ...
- Android VS IOS
时间: IOS:var d = new Date("2018-04-19 14:23:00".replace(/-/g, "/")); (d = new Dat ...
- 智能手机的耗电特征及APP耗电量测试的两种方法
文章陈述了手机发展趋势及耗电特性,集中讨论了时下最为关心的智能手机耗电问题,并介绍了测量手机软件耗电量的两种方法.此外还解释了为何运营商此前会提出收取微信的费用,心跳机制是什么. 美国著名手机公司Pa ...
- FileOutPutStream 的写操作
package xinhuiji_day07; import java.io.File;import java.io.FileNotFoundException;import java.io.File ...