我和你同样的问题,不知为啥
```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
char c;
int cal(char a, int b, int c)
{
if (a == '+') return b + c;
if (a == '-') return b - c;
if (a == '*') return b * c;
return b + c;
}
int getlen(int a)
{
int len = 0, flag = 0;
if (a < 0)
{
flag = 1;
a = -a;
}
while (a)
{
a /= 10;
len++;
}
return len + flag;
}
void process(string s)
{
int a = 0, b = 0, i = 0;
int len = s.length(), ans=0;
if (s[0] >= 'a' && s[0] <= 'z')
{
c = s[0];
if (c == 'a') c = '+';
else if (c == 'b') c = '-';
else c = '*';
i = 2;
}
while (s[i] != ' ' && i < len) { a = a * 10 + s[i] - '0'; i++;}
i++;
while (i < len) { b = b * 10 + s[i] - '0'; i++;}
cout << a << c << b << "=" << cal(c, a, b) << endl;
ans = getlen(cal(c, a, b))+getlen(a)+getlen(b)+2;
cout << ans << endl;
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(NULL);
// freopen("1.in", "r", stdin);
// freopen("test.out", "w", stdout);
int n;
cin >> n;
getline(cin, s);
for (int i = 1; i <= n; i++)
{
getline(cin, s);
process(s);
}
// clear
s.clear();
return 0;
}
```
by caomuyilin @ 2022-06-23 19:37:22
我也一样
by pingyyds @ 2022-07-03 09:57:49
不会是题目的测试数据不对吧
by pingyyds @ 2022-07-03 09:58:41
虽然我是一个蒟蒻,但我还是好心地提醒一下洛谷洛谷的测试数据末尾会有/n,所以你用getline会多读入一个/n,而你本地的Windows却不会
by LzxQwQ @ 2022-07-06 16:50:25