0
0
已采纳
王文博
缔造者之神
缔造者之神
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
char a1[100],b1[100];
int a[100],b[100],c[100],lena,lenb,lenc,i,x;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));//清空
gets(a1);
gets(b1);//字符数组读入,此乃高精度加法,算最简单的一个
lena=strlen(a1);
lenb=strlen(b1);
for(int i=0;i<=lena-1;i++) a[lena-i]=a1[i]-48;
for(int i=0;i<=lenb-1;i++) b[lenb-i]=b1[i]-48;//将加数放入int数组当中
lenc=1;
x=0;
while(lenc<=lena||lenc<=lenb)
{
c[lenc]=a[lenc]+b[lenc]+x;//两个数加起来
x=c[lenc]/10;
c[lenc]%=10;
lenc++;
}
c[lenc]=x;
if(c[lenc]==0) lenc--;
for(int i=lenc;i>=1;i--) cout<<c[i];
cout<<endl;//好习惯
return 0;//保险起见
}
高精度加法模板
0
0
0
0
李奕歌
初级天翼
初级天翼
看回放要币问老师为啥
不知道为啥WA0
#include<iostream>
using namespace std;
int main(){
long long a,n[2]={0,1};
cin>>a;
if(a%2==0){
while(a!=0){
n[0]+=a%10;
a/=10;
}
cout<<"H="<<n[0];
return 0;
}else{
while(a!=0){
n[1]*=a%10;
a/=10;
}
cout<<"J="<<n[1];
return 0;
}
return 0;
}
0
0
朱小川
缔造者
缔造者
我也是,直接爆0
**核心
while(n!=0) { a[i]=n%10; n/=10; c++; i++; } if(n1%2==0) { for(int j=1;j<=c;j++) s+=a[j]; cout<<"H="<<s; } else { for(int j=1;j<=c;j++) s1*=a[j]; cout<<"J="<<s1;
0
0
0
曹博扬
初级天翼
初级天翼
1096标准模板
#include<iostream>
#include<cstring>
using namespace std;
int n;
string s1,s2;
int a[200],b[200],c[200];
string add(string s1,string s2){
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
a[0]=s1.size();
for(int i=1;i<=a[0];i++){
a[i]=s1[s1.size()-i]-'0';
}
b[0]=s2.size();
for(int i=1;i<=b[0];i++){
b[i]=s2[s2.size()-i]-'0';
}
c[0]=max(a[0],b[0]);
int jw=0;
for(int i=1;i<=c[0];i++){
c[i]=a[i]+b[i]+jw;
jw=c[i]/10;
c[i]%=10;
}
if(jw>0){
c[0]++;
c[c[0]]=1;
}
string s="";
for(int i=c[0];i>=1;i--){
s+=char(c[i]+'0');
}
return s;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>s1>>s2;
cout<<add(s1,s2)<<endl;
}
return 0;
}
a+b