ilovexinxin @ 2022-02-17 18:06:48
#include<bits/stdc++.h>
using namespace std;
int num(int x) {
if (x) {
int t = 0, n = x;
while (abs(x)) {
x /= 10;
t++;
}
if (n > 0) {
return t;
}
else {
return t + 1;
}
}
else {
return 1;
}
}
int main() {
int n;
cin >> n;
getchar();
string s;
char c;
for (int i = 0; i < n; i++) {
int sum[2] = { 0 }, t = 0, a, b;
getline(cin,s);
bool f = false;
for (int j = 0; s[j]; j++) {
if (s[j] == 'a' || s[j] == 'b' || s[j] == 'c') {
c = s[j];
f = true;
}
else {
if (s[j] != ' ') {
sum[t] = sum [t] * 10 + s[j] - '0';
}
if (s[j] == ' ' || j + 1 == s.size()) {
if (f) f = !f;
else {
t++;
}
}
}
}
a = sum[0], b = sum[1];
int n1 = num(a), n2 = num(b), n3;
switch (c) {
case 'a':
cout << a << "+" << b << "=" << a + b << endl;
n3 = num(a + b);
break;
case 'b':
cout << a << "-" << b << "=" << a - b << endl;
n3 = num(a - b);
break;
case 'c':
cout << a << "*" << b << "=" << a * b << endl;
n3 = num(a * b);
break;
}
cout << n1 + n2 + n3 + 2 << endl;
}
return 0;
}
by RockyYue @ 2022-02-17 19:21:32
那得看你编译器版本了qwq