wlimcoming @ 2021-02-14 16:00:52
#include<bits/stdc++.h>
using namespace std;
int getlen(int x)
{
string a = to_string(x);
return a.length();
}
int main()
{
int n;
cin >> n;
bool flag = true;
string s;
char fh;
int x1, x2, a1, a2;
char temp;
cin.ignore();
while (n--)
{
getline(cin, s);
temp = s[0];
if (!isdigit(temp))
{
fh = temp;
a1=s.find(' ');
string s2 = s.substr(a1 + 1);
a2 = s2.find(' ');
x1 = atoi(s2.substr(0, a2).c_str());
x2 = atoi(s2.substr(a2 + 1).c_str());
}
else
{
a1 = s.find(' ');
x1 = atoi(s.substr(0, a1).c_str());
x2 = atoi(s.substr(a1 + 1).c_str());
}
switch (fh)
{
case 'a':cout << x1 << "+" << x2 << "=" << x1 + x2 << endl;
cout << getlen(x1) + getlen(x2) + getlen(x1 + x2) + 2 << endl;
break;
case 'b':cout << x1 << "-" << x2 << "=" << x1 - x2 << endl;
cout << getlen(x1) + getlen(x2) + getlen(x1 - x2) + 2 << endl;
break;
case 'c':cout << x1 << "*" << x2 << "=" << x1 * x2 << endl;
cout << getlen(x1) + getlen(x2) + getlen(x1 * x2) + 2 << endl;
break;
}
}
}
by wlimcoming @ 2021-02-14 16:02:33
刚开始是全都RE然后不知道改了哪里就成全WA了,但是测试样例是对的,求助大佬。。。
by wlimcoming @ 2021-02-14 16:06:09
记起来了好像是把stoi改成了atoi然后就从re变成wa了
by PragmaGCC @ 2021-02-14 17:11:15
getline
?
by wlimcoming @ 2021-02-16 13:14:36
@PragmaGCC 对啊,这样不是输入带有空格的字符串吗
by PragmaGCC @ 2021-02-16 13:15:43
@wlimcoming 我是说这东西容易锅,你应该就是因为这个WA了
by wlimcoming @ 2021-02-16 13:19:25
@PragmaGCC emmmm,那应该用什么来输入呢
by PragmaGCC @ 2021-02-16 13:21:10
@wlimcoming 手写个读入不行吗
by wlimcoming @ 2021-02-16 13:30:19
@PragmaGCC 谢谢大佬,终于AC了