以下为本人代码。
说明:(乘法为高精乘高精,除法为高精除低精)
高精度代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=4e3+10;
string a,b,c,e;
long long d;
bool fl;
string jian(string s1,string s2){
int t=0,f;
string an,an1;
if(s1.size()<s2.size()) {fl=1;return jian(s2,s1);}
else if (s1.size()==s2.size()&&s1<s2) {fl=1;return jian(s2,s1);}
while(s2.size()<s1.size()) s2='0'+s2;
int l1=s1.size();
for(int i=l1-1;i>=0;i--){
int q=s1[i]-'0',w=s2[i]-'0';
q=q+t-w;
t=0;
if(q<0){
q=q+10;
t=-1;
}
char f=q+'0';
an=f+an;
}
int l2=an.size(),cn=0;
for(int i=0;i<l2;i++){
if(an[i]=='0') cn++;
else break;
}
for(int i=cn;i<l2;i++){
an1=an1+an[i];
}
if(fl) an1='-'+an1;
if(an1=="") return "0";
else return an1;
}
string add(string s1,string s2){
if(s1[0]=='-'||s2[0]=='-') return jian(s1,s2);
string an;
if(s1.size()<s2.size()) return add(s2,s1);
while(s2.size()<s1.size()){
s2='0'+s2;
}
int l1=s1.size(),t=0;
char f;
for(int i=l1-1;i>=0;i--){
t+=(s1[i]-'0')+(s2[i]-'0');
f=(t%10)+'0';
t/=10;
an=f+an;
}
if(t) f=(t%10)+'0',an=f+an;
return an;
}
string cheng(string s1,string s2){
int a[N],b[N],c[N],t,cnt,l1,l2;
string an;
l1=s1.size(),l2=s2.size();
for(int i=l1-1;i>=0;i--){
a[l1-i-1]=s1[i]-'0';
}
for(int i=l2-1;i>=0;i--){
b[l2-i-1]=s2[i]-'0';
}
for(int i=0;i<=l1+1;i++){
for(int j=0;j<=l2+1;j++){
c[i+j]+=a[i]*b[j]+t;
t=c[i+j]/10;
c[i+j]%=10;
}
}
cnt=l1+l2+2;
while(c[cnt]==0) cnt--;
for(int i=cnt;i>=0;i--){
char f=c[i]+'0';
an=an+f;
}
if(an!="") return an;
else return "0";
}
string chu(string s1,long long b){
string an,an1;
char f;
long long h;
for(int i=0;i<s1.size();i++){
h=h*10+(s1[i]-'0');
f=(h/b)+'0';
h=h%b;
an=an+f;
}
int cnt=0;
while(an[cnt]=='0') cnt++;
if(cnt==an.size()) {
return "0";
}
else{
for(int i=cnt;i<an.size();i++){
an1+=an[i];
}
return an1;
}
}
int main(){
cin>>a>>b>>c>>d>>e;
cout<<jian(chu(cheng(add(a,b),c),d),e);
}
对拍代码:
#include <stdio.h>
using namespace std;
unsigned long long a,b,c,d,e;
int main(){
scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e);
printf("%lld",(a+b)*c/d-e);
}
#include <bits/stdc++.h>
using namespace std;
int main(){
srand(time(0));
long long a=rand()%300000;
long long b=rand()%300000;
long long c=rand()%300000;
long long d=rand()%300000;
long long e=rand();
printf("%lld %lld %lld %lld %lld",a,b,c,d,e);
}
#include <bits/stdc++.h>
using namespace std;
int cnt=1;
int main(){
while(1){
system("./shujv > 1.out");
system("./biao < 1.out > biao.out");
system("./bao < 1.out >bao.out");
if(!system("diff bao.out biao.out")){ //windows 转为fc
printf("AC %d\n",cnt);
++cnt;
}
else{
printf("WA\n");
break;
}
}
}
g++ biao.cpp -o biao
if [ $? -eq 0 ]
then
g++ bao.cpp -o bao
if [ $? -eq 0 ]
then
g++ shujv.cpp -o shujv
if [ $? -eq 0 ]
g++ pai.cpp -o pai
then
./pai
fi
fi
fi
我的博客即将同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=120u00svmx7fb