https://www.luogu.com.cn/problem/P1957
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int ws(int);
void jia();
void jian();
void cheng();
int n, length;
string a;
int main() {
cin >> n;
while(n-- >= 0) {
getline(cin, a);
length = a.length();
if(isdigit(a[0]) || a[0] == 'a')
jia();
else if(a[0] == 'b')
jian();
else if(a[0] == 'c')
cheng();
}
return 0;
}
int ws(int x) {
int w = 0;
if(x < 0) {
x = abs(x);
w++;
}
while(x > 0) {
x /= 10;
w++;
}
return w;
}
void jia() {
int i = 0, js = 0, bjs = 0;
if(!isdigit(a[i]))
i += 2;
while(a[i] != ' ') {
bjs *= 10;
bjs += a[i] - '0';
i++;
}
i++;
while(i < length) {
js *= 10;
js += a[i] - '0';
i++;
}
int h = bjs + js;
int l = ws(bjs) + ws(js) + ws(h) + 2;
printf("%d+%d=%d\n%d\n", bjs, js, h, l);
return ;
}
void jian() {
int i = 0, js = 0, bjs = 0;
if(!isdigit(a[i]))
i += 2;
while(a[i] != ' ') {
bjs *= 10;
bjs += a[i] - '0';
i++;
}
i++;
while(i < length) {
js *= 10;
js += a[i] - '0';
i++;
}
int h = bjs - js;
int l = ws(bjs) + ws(js) + ws(h) + 2;
printf("%d-%d=%d\n%d\n", bjs, js, h, l);
return ;
}
void cheng() {
int i = 0, cs = 0, bcs = 0;
if(!isdigit(a[i]))
i += 2;
while(a[i] != ' ') {
bcs *= 10;
bcs += a[i] - '0';
i++;
}
i++;
while(i < length) {
cs *= 10;
cs += a[i] - '0';
i++;
}
int h = bcs * cs;
int l = ws(bcs) + ws(cs) + ws(h) + 2;
printf("%d*%d=%d\n%d\n", bcs, cs, h, l);
return ;
}