gzp192 @ 2022-04-04 22:53:17
#include<iostream>
#include<ctype.h>
#include<string.h>
#include<vector>
#include <sstream>
using namespace std;
int main(){
int n;
cin >> n;
char temp;
string answer[60];
string s[60];
for (int i = 0; i < n+1;i++){
getline(cin, s[i]);
}
for (int i = 1; i < n+1; i++)
{
vector<int> num;
for (int j = 0; j < s[i].length(); j++)
{
if (isspace(s[i][j]))
{
num.push_back(j);
}
}
string s1, s2, s3;
int s4;
if (num.size() == 2)
{
temp = s[i][0];
s1 = string(s[i], num[0] + 1, num[1] - num[0] - 1);
s2 = string(s[i], num[1] + 1, s[i].length() - num[1] - 1);
answer[i].append(s1);
if (temp == 'a')
{
answer[i].append("+");
s4 = (atoi(s1.c_str()) + atoi(s2.c_str()));
}
if (temp == 'b')
{
answer[i].append("-");
s4 = (atoi(s1.c_str()) - atoi(s2.c_str()));
}
if (temp == 'c')
{
answer[i].append("*");
s4 = (atoi(s1.c_str()) * atoi(s2.c_str()));
}
answer[i].append(s2);
answer[i].append("=");
stringstream ss;
ss << s4;
ss >> s3;
answer[i].append(s3);
cout << answer[i] << endl<<answer[i].length();
if(i<n) cout << endl;
}
if (num.size() == 1)
{
s1 = string(s[i], 0, num[0]);
s2 = string(s[i], num[0] + 1, s[i].length() - num[0] - 1);
answer[i].append(s1);
if (temp == 'a')
{
answer[i].append("+");
s4 = (atoi(s1.c_str()) + atoi(s2.c_str()));
}
if (temp == 'b')
{
answer[i].append("-");
s4 = (atoi(s1.c_str()) - atoi(s2.c_str()));
}
if (temp == 'c')
{
answer[i].append("*");
s4 = (atoi(s1.c_str()) * atoi(s2.c_str()));
}
answer[i].append(s2);
answer[i].append("=");
stringstream ss;
ss << s4;
ss >> s3;
answer[i].append(s3);
cout << answer[i] << endl
<< answer[i].length();
if(i<n) cout << endl;
}
}
}
by _Remake_ @ 2022-04-04 23:12:04
如果是本地AC洛谷WA,你可以尝试在洛谷IDE上运行此程序
by icezhk @ 2022-06-18 22:56:46
@Remake
感谢大佬提醒!