View Code of Problem 3855

#include<stdio.h>
#include<string.h>
int main()
{
	int n,len,i,n1,n2,tmp,tag,sum;
	char s[100010];
	scanf("%d",&n);
	while(n--){
		scanf("%s",s);
		len=strlen(s);
		sum=0;
		tag=1;
		for(i=0;i<len;++i){
			tmp=0;
		
			if(s[i]=='+')
				tag=1;
			else if(s[i]=='-')
				tag=-1;
			else{
				while(s[i]>='0'&&s[i]<='9'&&i<len){
					tmp=tmp*10+s[i]-'0'; 
					i++;
				}
				sum+=tmp*tag;
				i--;
			}			
		}
		printf("%d\n",sum);
		
	} 
	return 0;
}

Double click to view unformatted code.


Back to problem 3855