首页 > 其他分享 >PAT甲级1005 Spell It Right

PAT甲级1005 Spell It Right

时间:2024-10-10 23:22:09浏览次数:3  
标签:case Right int sum Spell ssr contains 1005 line

介绍

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 (≤10的100次方).

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.

代码
 

#include<bits/stdc++.h>
using namespace std;
string word[11]={"zero","one","two","three","four","five","six","seven","eight","nine"};
int main()
{
	string ssr;
	cin>>ssr;
	int n=ssr.length();
	int sum=0;
	for(int i=0;i<=n-1;++i)
	{
		sum+=(ssr[i]-'0');
	}
	ssr=to_string(sum);
	cout<<word[ssr[0]-'0'];
	for(int i=1;i<=ssr.length()-1;++i)
	{
		cout<<" "<<word[ssr[i]-'0'];
	}
	return 0;
 } 


 

标签:case,Right,int,sum,Spell,ssr,contains,1005,line
From: https://blog.csdn.net/song0789/article/details/142832186

相关文章

  • XYD1005CSPS
    T1传送门[最短路,二分答案]Description无向连通图,求出一个最小的\(x\),使得每两点之间存在一条路径可以划分成不超过\(k\)段路径,且每段路径长度不超过\(x\),只能从节点处切割,不能从边中间划分。\(n\le100\),无重边自环。Solution\(n\)非常小,又要考虑每两个点,自然想到全......
  • Day 24 贪心算法part02| LeetCode 122.买卖股票的最佳时机II,55.跳跃游戏,45.跳跃游戏II
    122.买卖股票的最佳时机II局部最优:每天的正利润全局最优:每天的正利润之和121.买卖股票的最佳时机classSolution{publicintmaxProfit(int[]prices){intres=0;for(inti=1;i<prices.length;i++){i......
  • Gym 100543G Virus synthesis 题解
    Solution首先只考虑回文串的答案;我们重点考虑的是偶回文串结论:对于偶回文串\(u\),从其最长的长度小于等于他的一半的回文后缀,或其父亲转移过来,一定是最优的证明:设\(u\)的一个回文子串为\(v\)(不是父亲),你要让\(v\tou\)的转移最优首先\(v\)不能跨过\(u\)的中点,因为此......
  • 20241005-顺路
    又顺了一次路呢,感觉现在对距离的感知越来越清晰了。吃完饭准备去买雪糕结果lzm就看到了zyx,真是巧呢,于是买完雪糕跟他们顺路回去了。其实想记的不是这个,是因为最近我又莫名有很强烈的自卑感了。感觉自己这种心理很有问题但是就是克制不住,OI和whk的学习有,甚至连打个乒乓球......
  • [AGC017C] Snuke and Spells
    题意给定\(n\)个球,每个球上有一个数字\(a_i\)。每当魔法少女施展魔法时,会将写着当前球的数量的球全部消除。\(q\)次修改球的值,你需要在基础上修改最小的次数使得这\(n\)个球可以被魔法少女消除,求出你修改的最小次数。\(n\le2\times10^5\)。Sol神题!由于修改至......
  • 代码随想录算法训练营 | 122.买卖股票的最佳时机II,55. 跳跃游戏,45.跳跃游戏II,1005.K次
    122.买卖股票的最佳时机II题目链接:122.买卖股票的最佳时机II文档讲解︰代码随想录(programmercarl.com)视频讲解︰买卖股票的最佳时机II日期:2024-10-03想法:本来还在想什么时候买股票,结果只需要考虑每天的正收益累加就是最大的收益了。Java代码如下:classSolution{public......
  • 828华为云征文|部署个人文档管理系统 Docspell
    828华为云征文|部署个人文档管理系统Docspell一、Flexus云服务器X实例介绍二、Flexus云服务器X实例配置2.1重置密码2.2服务器连接2.3安全组配置2.4Docker环境搭建三、Flexus云服务器X实例部署Docspell3.1Docspell介绍3.2Docspell部署3.3Docspell使用四、总......
  • PlayWright检测用户登录保存Cookie
    背景本需求以稀土掘金社区为例采用PlayWright包pipinstallplaywright思路用户打开软件,提示进入浏览器登录后进行操作将expect_response()的超时时间设置为无限毫秒expect_response()函数就是等待指定响应发生的方法通过手动抓包发现掘金社区登陆成功后响应返回接口地......
  • WPF Combobox switch up and down then show the big picture in the right part
    <ComboBoxx:Name="cbx"Grid.Row="0"Grid.Column="0"SelectedIndex="0"ItemsSource="{StaticResourcebooksData}"FontSize="20"......
  • WPF Expander ExpandDirection Left,Right,Up,Down
    //xaml<Windowx:Class="WpfApp378.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mi......