#include<stdio.h> #include<math.h> #include<string.h> int main(){ int t; scanf("%d",&t); while(t--){ char s[1000]; scanf("%s",s); int sum=0; int b; int flag=1; int i; for(i=0;i<strlen(s);){ if(s[i]=='+'||s[i]=='-'){ if(s[i]=='+'){ flag=1; }else{ flag=-1; } i++; b=0; while(s[i]>='0'&&s[i]<='9'){ b=b*10+s[i]-'0'; i++; } sum+=b*flag; }else{ b=0; while(s[i]>='0'&&s[i]<='9'){ b=b*10+s[i]-'0'; i++; } sum+=b; } } printf("%d\n",sum); } return 0; } |
Double click to view unformatted code.