#include<iostream> #include<cstring> #include<algorithm> #include<queue> #include<stdio.h> #include<string.h> #include<cmath> using namespace std; int main() { int times; cin>>times; while(times--) { string str; cin>>str; int flag=1; int num=0,sum=0; for(int i=0;i<str.length();i++) { if(str[i]=='+') { flag=1; } else if(str[i]=='-') { flag=0; } else { int tem=0; while(1){ if(str[i]>='0'&&str[i]<='9') { tem=tem*10+str[i]-'0'; i++; } else {i--;break;} } // cout<<tem<<endl; if(flag==1) sum+=tem; else sum-=tem;} //flag=0; } cout<<sum<<endl; } return 0; } |
Double click to view unformatted code.