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