紧急求救!!!!!!!!!!!!!!!!
2024-12-15 14:33:38
发布于:北京
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
char s[N];
struct bignum {
int len,op,a[N];
bignum(){
len =0;
op=1;
for(int i=0;i<N;i++) a[i]=0;
memset(a,0,sizeof(a));
}
void push(){
for(int i=1;i<=len;i++){
if(a[i]>=10){
if(i==len) len++;
a[i+1]+=a[i]/10;
a[i]%=10;
}
}
}
void read() {
cin >> s;
int len1 = strlen(s);
for (int i = 0; i < len1; i++) {
a[i + 1] = s[len - 1 - i] - '0';
}
}
void write() {
if(op==-1) a[len]*=-1;
for(int i=len;i>=1;i--) cout<<a[i];
cout<<endl;
}
friend bignum operator +(bignum x,bignum y){
bignum z;
z.len=max(x.len,y.len);
for(int i=1;i<=z.len;i++)
z.a[i] = x.a[i]+y.a[i];
z.push();
return z;
}
friend bool operator <(const bignum &x,const bignum &y){
if(x.len!=y.len) return x.len<y.len;
for(int i=x.len;i>=1;i--) if(x.a[i]!=y.a[i]) return x.a[i]<y.a[i];
return 0;
}
friend bignum operator -(bignum x,bignum y){
bignum z;
if(x<y){
z.op=-1;
swap(x.a,y.a);swap(x.len,y.len);
}
for(int i=x.len;i>=1;i--) z.a[i]=x.a[i]-y.a[i];
for(int i=1;i<=x.len;i++){
if(z.a[i]<0){
z.a[i]+=10;
z.a[i+1]--;
}
}
for(int i=x.len;i>=1;i--){
if(z.len==0&& z.a[i]==0) continue;
else if(z.len==0) z.len=i;
}
if(z.len==0) z.len=1;
return z;
}
friend bignum operator *(bignum x,bignum y) {
bignum z;
if((x.len<=1&&x.a[1]==0)||(y.len<=1&&y.a[1]==0)){
z.len=1;
return z;
}
z.len=x.len+y.len-1;
for (int i = 1; i <= x.len; i++)
for (int j = 1; j <= y.len; j++)
z.a[i+j-1]+=x.a[i]*y.a[j];
z.push();
return z;
}
friend bignum operator /(bignum x,long long y){
long long t=0;
bignum z;
for(int i=x.len;i>=1;i--){
t=t*10+x.a[i];
if(t>=y){
if(z.len==0) z.len=i;
z.a[i]=t/y,t%=y;
}
}
return z;
}
friend long long operator %(bignum x,long long y){
long long t=0;
bignum z;
for(int i=x.len;i>=1;i--){
t=t*10+x.a[i];
if(t>=y){
if(z.len==0) z.len=i;
z.a[i]=t/y,t%=y;
}
}
return t;
}
};
int main(){
bignum x,y;
long long z;
x.read();y.read();
cin>>z;
(x+y).write();
(x-y).write();
(x*y).write();
(x/z).write();
cout<<x%z;
return 0;
}
为啥输入不了字符!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
一级标题
一级标题
全部评论 12
2024-12-15 来自 北京
0ding
2024-12-15 来自 北京
0救我·
2024-12-15 来自 北京
0救我
2024-12-15 来自 北京
0顶
2024-12-15 来自 北京
0顶
2024-12-15 来自 北京
0顶
2024-12-15 来自 北京
0顶
2024-12-15 来自 北京
0顶
2024-12-15 来自 北京
0救救我!!!!!!
2024-12-15 来自 北京
0顶
2024-12-15 来自 北京
0顶顶顶顶
2024-12-15 来自 北京
0
有帮助,赞一个