真正的A+B
#include<bits/stdc++.h>using namespace std;
char a,b;
int ia,ib,ic;
int main(){
int jinwei = 0;
int temp = 0,len;
scanf("%s",a);
scanf("%s",b);
for (int i = strlen(a)-1;i>=0;i--){
ia = a - '0';
temp ++;
}
temp = 0;
for (int i = strlen(b)-1;i>=0;i--){
ib = b - '0';
temp++;
}
if (strlen(a) > strlen(b)) {
len = strlen(a);
}
else{
len = strlen(b);
}
for (int i = 0;i<=len;i++){
if (jinwei == 1){
ic = ia + ib + 1;
jinwei = 0;
}
else{
ic = ia +ib;
}
if (ic >=10){
jinwei = 1;
ic -= 10;
}
}
for (int i = len;i>=0;i--){
if (ic ==0&&i == len){
}
else{
cout<<ic;
}
}
}
这才叫a+b
(高精度运算) 不是要用线段树来做么 #include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
using cpp_int = boost::multiprecision::cpp_int;
using std::cin, std::cout, std::endl;
int main() {
cpp_int a, b; cin >> a >> b;
cout << a + b << endl;
return 0;
}
#include <bits/stdc++.h>
#define ll long long
#define N 100000
using namespace std;
int sz, rev, tag, sum, ch, fa, val;
int n, m, rt, x;
void push_up(int x){
sz = sz] + sz] + 1;
sum = sum] + sum] + val;
}
void push_down(int x){
if(rev){
swap(ch, ch);
if(ch) rev] ^= 1;
if(ch) rev] ^= 1;
rev = 0;
}
if(tag){
if(ch) tag] += tag, sum] += tag;
if(ch) tag] += tag, sum] += tag;
tag = 0;
}
}
void rotate(int x, int &k){
int y = fa, z = fa];
int kind = ch == x;
if(y == k) k = x;
else ch==y] = x;
fa = z; fa = x; fa[!kind]] = y;
ch = ch[!kind]; ch[!kind] = y;
push_up(y); push_up(x);
}
void splay(int x, int &k){
while(x != k){
int y = fa, z = fa];
if(y != k) if(ch == x ^ ch == y) rotate(x, k);
else rotate(y, k);
rotate(x, k);
}
}
int kth(int x, int k){
push_down(x);
int r = sz]+1;
if(k == r) return x;
if(k < r) return kth(ch, k);
else return kth(ch, k-r);
}
void split(int l, int r){
int x = kth(rt, l), y = kth(rt, r+2);
splay(x, rt); splay(y, ch);
}
void rever(int l, int r){
split(l, r);
rev]] ^= 1;
}
void add(int l, int r, int v){
split(l, r);
tag]] += v;
val]] += v;
push_up(ch]);
}
int build(int l, int r, int f){
if(l > r) return 0;
if(l == r){
fa = f;
sz = 1;
return l;
}
int mid = l + r >> 1;
ch = build(l, mid-1, mid);
ch = build(mid+1, r, mid);
fa = f;
push_up(mid);
return mid;
}
int asksum(int l, int r){
split(l, r);
return sum]];
}
int main(){
//总共两个数
n = 2;
rt = build(1, n+2, 0);//建树
for(int i = 1; i <= n; i++){
scanf("%d", &x);
add(i, i, x);//区间加
}
rever(1, n);//区间翻转
printf("%d\n", asksum(1, n));//区间求和
return 0;
} 《挑战A+B最长代码》 sfqxx 发表于 2023-7-28 22:40
《挑战A+B最长代码》
但是介个可以计算很大的数
超过了long long sfqxx 发表于 2023-7-28 22:40
《挑战A+B最长代码》
泰裤辣 zhangjinxuan 发表于 2023-7-28 22:30
不是要用线段树来做么
用字符串也行{:10_257:} 香蕉那个不拿拿 发表于 2023-7-28 22:54
但是介个可以计算很大的数
超过了long long
{:9_217:} 我也来秀一下{:10_279:}
#include <bits/stdc++.h>
using namespace std;
struct bint{
int len;
int t;
bint(){
memset(t, 0, sizeof(t));
len = 0;
}
bint(const string &s){
memset(t, 0, sizeof(t));
len = s.length();
for (int i = 0; i < len; i++){
t = s - '0';
}
}
void print(){
for (int i = 0; i < len; i++){
cout << t;
}
cout << endl;
}
bint operator=(const bint &b){
len = b.len;
memcpy(t, b.t, len * sizeof(int));
return *this;
}
bint operator+(const bint &b) const{
bint c;
c.len = max(len, b.len);
int carry = 0;
for (int i = 0; i < c.len; i++){
int x = t + b.t + carry;
c.t = x % 10;
carry = x / 10;
}
if (carry){
c.t = carry;
}
return c;
}
bint operator*(const bint &b) const{
bint c;
for (int i = 0; i < len; i++){
int carry = 0;
for (int j = 0; j < b.len; j++){
int x = t * b.t + c.t + carry;
c.t = x % 10;
carry = x / 10;
}
if (carry){
c.t += carry;
}
}
c.len = len + b.len;
while (c.len > 1 && c.t == 0){
c.len--;
}
return c;
}
};
int main(){
string a, b;
cin >> a >> b;
bint c(a), d(b);
bint ans_jia = c + d;
ans_jia.print();
return 0;
} print(sum(map(int, input().split()))){:10_256:} tommyyu 发表于 2023-7-29 10:34
一点也不节省,逗号后面的空格,赶紧吃了{:10_256:} zhangjinxuan 发表于 2023-7-29 11:36
一点也不节省,逗号后面的空格,赶紧吃了
print(sum(map(int,input().split())))
#___________
#| o/
#| /
#| /
#| / " "
#| \
#| \
#| \
#|_________\{:10_256:} tommyyu 发表于 2023-7-29 11:42
{:10_277:}
页:
[1]