HDU多校练习第一场4608——I_Number

题目:点击打开链接

水题一道,刚开始写了一发模拟,后来发现所谓的10^5是个length……果断加了个大数枚举,过了,今天换了个样式重写了个。

易于推出,两个数之间的最大差值为20.

#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <string>
using namespace std;

const int maxn=100001;

int max(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}

class bign
{
	public:
		int len;
		int s[maxn];
};


bign addbignum(bign a,bign b)
{
	bign c;
	c.len=0;
	for(int i=0,g=0;g||i<max(a.len,b.len);i++)
	{
		int x=g;
		if(i<a.len)
			x+=a.s[i];
		if(i<b.len)
			x+=b.s[i];
		c.s[c.len++]=x%10;
		g=x/10;
	}
	return c;
}

int main()
{
	int testcase;
	cin>>testcase;
	for(int z=1;z<=testcase;z++)
	{
		int res;
		string tmpa,tmpb;
		bign a,one;
		cin>>tmpa;
		a.len=tmpa.size();
		one.len=1;
		one.s[0]=1;
		
		for(int i=0;i<a.len;i++)
		{
			a.s[i]=tmpa[a.len-i-1]-'0';
		}
		
		a=addbignum(a,one);
		for(int j=0;j<=20;j++)
		{
			res=0;
			for(int i=0;i<a.len;i++)
			{
				res+=a.s[i];
			}
			if(res%10==0)
			{
				for(int p=a.len-1;p>=0;p--)
				{
					cout<<a.s[p];
				}
				cout<<endl;
				break;
			}
			
			a=addbignum(a,one);
		}
		

		
	}
	return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值