xqaz2wsx3edc @ 2023-07-19 17:27:23
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char ss[100000],oo[100000];
int a[510000],b[510000];
void add(int *a,int *b) {
if(a[0]<b[0])a[0]=b[0];
int cr=0;
for(int i=1; i<=a[0]; i++) {
a[i]+=b[i]+cr;
cr=a[i]/10;
a[i]%=10;
}
if(cr) {
a[0]++;
a[a[0]]=cr;
}
}
void t(int *a) {
scanf("%s",ss);
a[0]=strlen(ss);
for(int i=1; i<=a[0]; i++) {
a[i]=ss[a[0]-i]-'0';
}
}
void o(int *a) {
for(int i=a[0];i>0; i--) {
cout<<a[i];
}
}
int main() {
t(a);
t(b);
add(a,b);
o(a);
}
by Him_jntm @ 2023-07-24 13:13:50
@Lordlyt 6
by sz2107wx @ 2023-07-26 10:48:00
为什么要高精度```cpp
using namespace std; int main() { string s1,s2; cin>>s1>>s2; int a[10000000],b[10000000],c[100000000]; for(int i=0;i<s1.size();i++) { a[s1.size()-i-1]=s1[i]-'0'; } for(int i=0;i<s2.size();i++) { b[s2.size()-i-1]=s2[i]-'0'; } int len; if(s1.size()<s2.size()) len=s2.size(); else len=s1.size(); for(int i=0;i<=len;i++) { c[i]+=a[i]+b[i]; c[i+1]=c[i]/10; c[i]%=10; } while(len>0&&c[len]==0) len--; for(int i=len;i>=0;i--) { cout<<c[i]; } return 0; }
by wjl_100930 @ 2023-07-26 14:19:43
#include<bits/stdc++.h>
using namespace std;
#define 龙龙 long long
inline 龙龙 read()
{
register 龙龙 x=0,f=1;
register char ch=getchar();
while(!isdigit(ch))
{if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))
{x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*f;
}
int main()
{
cout<<read()+read();
return 0;
}
by DBL_MAX @ 2023-07-26 20:52:29
@Him_jntm 有必要定义sum吗?直接:
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b;
return 0;
}
结果: https://www.luogu.com.cn/record/117587452
by Him_jntm @ 2023-07-27 13:34:29
@Dumbo 我习惯了 这样也保险一点,说出来你可能不信 一些网站按照你这样不通过
by DBL_MAX @ 2023-07-27 18:14:58
@Him_jntm 但起码这道题能过
by 120103cww @ 2023-07-29 20:16:46
@Him_jntm sum不需要吧,直接输出a+b
by Lcq2011 @ 2023-08-08 09:52:46
a这,不需要高精
by __youzimo2014__ @ 2023-08-11 17:12:03
你要高精度就去P1601,这里只需要两个int就行了,不需要高精度
by Anoif @ 2023-09-29 17:53:44
@sz2107wx 大哥建议检查代码 (望丰展?使MD)