View Code of Problem 3855

#include<stdio.h>
#include<math.h>
#include<string.h>
//#include<algorithm>
#include <bits/stdc++.h>

using namespace std;


int main() {
	int T;
	scanf("%d",&T);
	while(T--) {
		char str[1000];
		scanf("%s",str);
		int biaoji=1;
		int temp=0;
		int sum=0;
		for(int i=0; i<strlen(str); i++) {
			if(str[i]=='+') {
				sum=sum+temp*biaoji;
				temp=0;
				biaoji=1;
			} else if(str[i]=='-') {
				sum=sum+temp*biaoji;
				temp=0;
				biaoji=-1;
			} else {
				temp=temp*10+str[i]-'0';
			}
		}
		sum=sum+temp*biaoji;

		printf("%d\n",sum);

	}
}

Double click to view unformatted code.


Back to problem 3855