5分,求助大佬!!!
查看原帖
5分,求助大佬!!!
1061599
Zimu_Q楼主2023/12/13 21:29
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;

int a[100001],b[100001],c[100001],tmp[100001];
void init(int *x){
	char s[305];
	cin >> s;
	x[0] = strlen(s);
	for(int i=0; i<x[0]; i++){
		x[x[0]-i] = s[i] - '0';
	}
}
void numcpy(int *p,int *q,int n){
	for(int j=1; j<=p[0]; j++){
		q[j+n-1] = p[j];
	}
	q[0] = p[0] + n - 1;
}
int compare(int *a,int *b){
	if(a[0]>b[0]) return 1;
	if(a[0]<b[0]) return -1;
	for(int i=a[0]; i>0; i--){
		if(a[i] > b[i]) return 1;
		if(a[i] < b[i]) return -1;
	}
	return 0;
}
void minu(int *a,int *b){
	int flag = compare(a,b);
	if(flag==0){
		a[0] = 0;
		return;
	}
	for(int i=1; i<=a[0]; i++){
		if(a[i] < b[i]){
			a[i+1]--;
			a[i] += 10;
		}
		a[i] = a[i] - b[i];
	}
	while(a[a[0]]==0 && a[0]>1) a[0]--;
}
void print(int *a){
	for(int i=a[0]; i>=1; i--){
		printf("%d",a[i]);
	}
}


int main(void){
	init(a);
	init(b);
	c[0] = a[0] - b[0] + 1;
	
	for(int i=c[0]; i>=1; i--){
		memset(tmp, 0, sizeof(tmp));
		numcpy(b,tmp,i);
		while(compare(a,tmp)>=0){
			c[i]++;
			minu(a,tmp);
		}
	
	
	}
	while(c[c[0]]==0 && c[0]>0) c[0]--;
	print(c);
	cout<<endl;

	return 0;
} 
2023/12/13 21:29
加载中...