PAT A1023

很简单,但是题中给的是不到20位的数字,已经超出了Int、long、long long的范围,double有效长度37足够了,但是不能用%运算,没查为什么,转为string接受数字。

#include<iostream>
#include<string>

using namespace std;

int main()
{
	string org;
	cin >> org;
	if (org == "0")
	{
		cout << "Yes" << endl;
		cout << 0;
		return 0;
	}
	string db;
	int ll = org.size();
	int a[10] = { 0 }, b[10] = { 0 }, ans[20] = { 0 }, i;
	int temp = 0, head = 0, j = 0;
	for (i = ll - 1; i >= 0; i--)
	{
		//cout <<"i=="<< i << endl;
		temp = (org[i] - '0') * 2;
		//cout << "temp="<<temp << endl;
		a[(org[i] - '0')]++;
		if (temp +head>=10)
		{
			ans[i]= temp - 10 + head;
			head = 1;
		}
		else
		{
			ans[i] =temp+head;
			head = 0;
		}
		b[ans[i]]++;
		//j++;
	}
	int flag = true;
	if (head)
	{
		cout << "No" << endl;
		cout << head;
		flag = false;
	}
	else
	{
		for (i = 0; i < 10; i++)
		{
			if (a[i] != b[i])
			{
				cout << "No" << endl;
				flag = false;
				break;
			}
		}
	}
	if (flag)
	{
		cout << "Yes" << endl;
	}
	for (i = 0; i < ll; i++)
	{
		cout << ans[i];
	}
	system("pause");
	return 0;
}

以后不能眼高手低了,这种题应该半小时想加写,给15min进行完善。很久不练手生了,来日再战!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值