View Code of Problem 3855

#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cctype>
using namespace std;

int main()
{
	int T,i,n;
	cin>>T;
	while( T-- )
	{
		string sk;
		int t1;
		cin>>sk;
		if( isdigit(sk[0]) )sk="+"+sk;
		int sum=i=0;
		while( i<sk.size() )
		{
			if( sk[i]=='+' )
			{
				//正常处理
				i++;
				t1=0;
				while( isdigit(sk[i]) )
				{
					t1=(sk[i]-'0')+t1*10;
					i++;
				}
				sum+=t1;
			}if( sk[i] =='-')
			{
				i++;
				t1=0;
				while( isdigit(sk[i]) )
				{
					t1=(sk[i]-'0')+t1*10;
					i++;
				}
				sum-=t1;
			}
		}
			cout<<sum<<endl;
	}
 	return 0;
}

Double click to view unformatted code.


Back to problem 3855