其实这是一道很简单的题,我还是遭一位博主误导了。
首先这是个二元运算,其实在输入数据时没必要一开始把全部看成字符。
完整代码如下:
#include <iostream>
#include <strstream>
#include<string>
using namespace std;
int main()
{
//是我想复杂了,它只是二元的
//我的评价是我又想复杂了;
int ans, res; char x;
int n;
int total;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> ans >> x >> res;
switch (x)
{
case'+':
total = ans + res;
break;
case'-':
total = ans - res;
break;
case'/':
total = ans/ res;
break;
case'*':
total = ans * res;
break;
default:
break;
}
cout <<ans<<x<<res<<'='<< total << endl;
}
return 0;
}