3 条题解
-
2Grow LV 6 MOD @ 2024-10-17 17:23:44
简单高精加
#include <bits/stdc++.h> using namespace std; int main(){ string a,b,c; bool f=0; cin >> a >> b; while(a.size()<b.size())a='0'+a; while(a.size()>b.size())b='0'+b; for(int i = a.size()-1;i>=0;i--){ // cout << a[i] << " " << b[i] << "\n"; if(f==0){ if(a[i]+b[i]-'0'-'0'>9){ f=1; c=char(a[i]+b[i]-'0'-10)+c; } else{ c=char(a[i]+b[i]-'0')+c; f=0; } } else{ if(a[i]+b[i]-'0'-'0'+1>9){ f=1; c=char(a[i]+b[i]-'0'-9)+c; } else{ c=char(a[i]+b[i]-'0'+1)+c; f=0; } } } if(f)cout << 1; cout << c; return 0; }
-
12024-10-17 14:05:54@
Ex.A+B Problem 官方题解
思路
本题是
__int128
模板题,直接上代码:代码
#include<bits/stdc++.h> #define int long long using namespace std; __int128 read() { __int128 res=0; char scan[1005]; scanf("%s",scan); for(int i=0;i<(int)strlen(scan);i++) res*=10,res+=scan[i]-'0'; return res; } void print(__int128 sum) { if(sum>9) print(sum/10); putchar(sum%10+'0'); } signed main() { __int128 a=read(),b=read(); print(a+b); return 0; }
read
是输入__int128
类型的函数,print
是输出。这里运用了递归。 -
02024-10-17 14:08:38@
简单高精加(
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; string jia(string a , string b){ string c = ""; int x[1005] = {} , y[1005] = {} , z[1005] = {}; for(int i = a.size() - 1, j = 1; i >= 0 ; i-- , j++)x[j] = a[i] - '0'; for(int i = b.size() - 1, j = 1; i >= 0 ; i-- , j++)y[j] = b[i] - '0'; int len = max(a.size(), b.size()); for(int i = 1; i <= len; i++){ z[i] += x[i] + y[i]; z[i + 1] += z[i] / 10; z[i] %= 10; } if(z[len + 1] > 0)len++; for(int i = len; i >= 1 ; i--)c += char(z[i] + '0'); return c; } string a , b; int main(){ cin >> a >> b; cout << jia(a , b); return 0; }
- 1