#include<bits/stdc++.h> using namespace std; long long visit[100005]; int main() { int T;cin>>T; for(int i=0;i<T;i++){ string s;cin>>s; if(isdigit(s[0])){ //只有一个运算符 int zhenghao=s.find('+'); int fuhao=s.find('-'); if(zhenghao!=-1){//3+2 int a=atoi(s.substr(0,zhenghao).c_str()); int b=atoi(s.substr(zhenghao+1).c_str()); cout<<a+b<<endl; }else{ int a=atoi(s.substr(0,fuhao).c_str()); int b=atoi(s.substr(fuhao+1).c_str()); cout<<a-b<<endl; } }else{ //有两个 int zhenghao=s.find('+',1); int fuhao=s.find('-',1); if(zhenghao!=-1){//3+2 int a=atoi(s.substr(0,zhenghao).c_str()); int b=atoi(s.substr(zhenghao+1).c_str()); cout<<a+b<<endl; }else{ int a=atoi(s.substr(0,fuhao).c_str()); int b=atoi(s.substr(fuhao+1).c_str()); cout<<a-b<<endl; } } } } |
Double click to view unformatted code.