【PAT 甲级】1005 Spell It Right

本文深入探讨了编程技术领域的各个方面,从基础的编程语言到高级的AI和区块链技术,全面覆盖了软件开发、数据处理、人工智能、云计算等多个子领域。通过详细解析各种关键技术点和应用实例,旨在帮助开发者深入了解并掌握现代编程技术的核心概念。
1005 Spell It Right (20)(20 分)

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.

Sample Input:

12345

Sample Output:

one five

我的代码如下:

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
	string s,p;
	int len,sum=0,length=1,c=0;
	cin>>s;
	len = s.size();

	for(int i=0;i<len;i++)
	{//求和
		sum+=s[i]-'0';
	}

	while(sum!=0||c==0)
	{
		p+=char(sum%10+'0');
		sum=sum/10;
		c++;
	}

	for(int i=c-1;i>=0;i--)
	{
		switch(p[i])
		{
		case'0':cout<<"zero";break;
		case'1':cout<<"one";break;
		case'2':cout<<"two";break;
		case'3':cout<<"three";break;
		case'4':cout<<"four";break;
		case'5':cout<<"five";break;
		case'6':cout<<"six";break;
		case'7':cout<<"seven";break;
		case'8':cout<<"eight";break;
		case'9':cout<<"nine";break;
		default:break;
		}
		if(i!=0)
		{
			cout<<' ';
		}
	}

	system("pause");
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值