#include<iostream> using namespace std; int getrel(int a,int b,char op) { if(op=='+') { return a+b; } else { return a-b; } } int main() { int t; cin>>t; int a,b; char op; while(t--) { cin>>a; while(scanf("%c",&op)!=EOF) //scanf可以读取回车,而cin不行 { if(op=='\n') { break; } cin>>b; a=getrel(a,b,op); } cout<<a<<endl; } } |
Double click to view unformatted code.