输入1+1
输出2
#include <iostream>
#include <string >
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ostream_iterator<int> output(cout," ");
string s;
getline(cin,s);
int count=0;
for(int i=0;i<s.size();i++)
{
if(s[i]=='+'||s[i]=='-')
count++;
}
if(count!=1)
cout<<0;
else
{
const char *st=s.c_str();
char *str=(char *)malloc(sizeof(char)*s.size());
strcpy(str,st);
char *p=strtok(str,"+");
vector<int> input;
vector<char> oper;
while(p)
{
input.push_back(atoi(p));
p=strtok(NULL,"+");
}
copy(input.begin(),input.end(),output);
if(s.find('+')!=string::npos)
cout<<(input[0]+input[1]);
else if(s.find('-')!=string::npos)
cout<<(input[0]-input[1]);
}
system("pause");
return 0;
}