PAT 1005 Spell It Right 字符串处理
2024-09-01 15:38:42
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every
digit of the sum in English.
Input Specification:
Each input file contains one test case. Each case occupies one line which contains an N (<= 10100).
Output Specification:
For each test case, output in one line the digits of the sum in English words. There must be one space
between two consecutive words, but no extra space at the end of a line.
Sample Input:
12345
Sample Output:
one five
题目意思:对所给的一个非负整数n,求各位之和的每一位英文读音。
解题思路:先求所给n的各位之和sum,转换成string,输出对应的每一位读音即可。
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
int i,sum=;
string str;
string ans;
string a[]={"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
cin>>str;
for(i=; i<str.size(); i++)
{
sum+=str[i]-'';
}
ans=to_string(sum);
cout<<a[ans[]-''];//第一个读音
for(i=;i<ans.size();i++)
{
cout<<" "<<a[ans[i]-''];
}
return ;
}
最新文章
- 敏捷转型历程 - Sprint4 回顾会
- JavaScript 闭包深入浅出
- python--基础学习(一)开发环境搭建,体验HelloWorld
- SpringMVC——接收请求参数和页面传参
- php注意事项2
- 第七章 管理类型(In .net4.5) 之 使用类型
- 用XAML做网页!!—页头
- 去除 MyEclipse updating index
- 异常:Error resolving template ";xxx";, template might not exist or might not be accessible...解决办法
- JDK源码看ArrayList和Vector的一些区别
- 代码:PC CSS(工作中用)
- poj-3279 poj-1753(二进制枚举)
- 03-Windows Server 2016 IIS的安装与配置
- Lintcode: Kth Largest Element 解题报告
- FZU 2105 Digits Count
- numpy中min函数
- 一位资深程序员大牛给予Java初学者的学习建议
- 简明 ES6 模块
- 【二分法】【尺取法】bzoj2348 [Baltic 2011]Plagiarism
- JSP常见知识点