poj2736大整数相减

 
#include<iostream>
#include<string.h>
using namespace std;
char s1[100];
char s2[100];
int a1[100];
int a2[100];

int main()
{
	int c[100];
	int i,j;
	int str1,str2;
	int n;
	cin>>n;
	for(int l=0;l<n;l++)
	{

		cin>>s1;
		cin>>s2;
		memset(a1,0,sizeof(a1));
		memset(a2,0,sizeof(a2));
		str1=strlen(s1);
		j=0;
		for(i=str1-1;i>=0;i--)
		{
			a1[j]=s1[i]-'0';
			j++;
		}
		str2=strlen(s2);
		j=0;
		for(i=str2-1;i>=0;i--)
		{
			a2[j]=s2[i]-'0';
			j++;
		}

		for(j=0;j<str1;j++)
		{
			if(a1[j]>=a2[j])
				c[j]=a1[j]-a2[j];
			else
			{
				a1[j+1]--;
				c[j]=a1[j]+10-a2[j];
			}
		}

		bool bianliang=false;
		for(i=j-1;i>=0;i--)
		{
			if(bianliang)
				cout<<c[i];
			else if(c[i])
			{
				cout<<c[i];
				bianliang=true;

			}
		}
		if(!bianliang)
			cout<<0;
		cout<<endl;

			
		
}


    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值