AliceJames @ 2023-07-26 13:02:44
#include <iostream>
using namespace std;
#include <string>
int calculator(char option, int num1, int num2)
{
switch(option)
{
case '+':
return num1 + num2;
case '-':
return num1 - num2;
case '*':
return num1 * num2;
}
}
string tostring(int x)
{
if(x == 0) return "0";
string flag = "";
if(x < 0)
{
flag = "-";
x = -x;
}
string dest = "";
int digit;
while(x > 0)
{
digit = x % 10;
x /= 10;
dest = (char)(digit + '0') + dest;
}
dest = flag + dest;
return dest;
}
string src_to_dest(string src, char& option)
{
int i = 0;
int num1 = 0, num2 = 0;
while(1)
{
if('0' <= src[i] && src[i] <= '9') break;
i++;
}
while(1)
{
if(!('0' <= src[i] && src[i] <= '9')) break;
num1 = num1 * 10 + src[i] - '0';
i++;
}
while(1)
{
if('0' <= src[i] && src[i] <= '9') break;
i++;
}
while(1)
{
if(!('0' <= src[i] && src[i] <= '9')) break;
num2 = num2 * 10 + src[i] - '0';
i++;
}
if(src[0] == 'a') option = '+';
else if(src[0] == 'b') option = '-';
else if(src[0] == 'c') option = '*';
int result = calculator(option, num1, num2);
string dest = tostring(num1) + option + tostring(num2) + "=" + tostring(result);
int size = dest.length();
dest += "\n" + tostring(size);
return dest;
}
void test01()
{
int q;
cin >> q;
cin.ignore();
string src;
string* dest = new string[q];
char option = '+';
for(int i = 0; i < q; i++)
{
getline(cin, src);
dest[i] = src_to_dest(src, option);
}
for(int i = 0; i < q; i++)
{
cout << dest[i] << endl;
}
delete[]dest;
}
void test02()
{
int q;
cin >> q;
cin.ignore();
string str = "99+999=1098\n11";
cout << str << endl;
}
int main()
{
test04();
return 0;
}
by AliceJames @ 2023-07-26 13:03:25
你问我我也不知道啊。。。你还是问别人吧
by AliceJames @ 2023-07-26 13:05:24
笨啊,你main()里调用的是test04()
by AliceJames @ 2023-07-26 13:05:56
你说得对,但是改成test01()依旧全WA
by Max6700 @ 2023-07-26 13:35:38
《自导自演》
我属实没看懂楼上在说啥