其他分享
首页 > 其他分享> > 仅加减的字符串求职

仅加减的字符串求职

作者:互联网

#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <string>
#include <algorithm>
using namespace std;
int main(void)
{	
	string s;
	while (cin>>s) {
		int t=0;
		vector<int> ans;
		char fu='#';
		for (int i = 0; i <= s.size();i++) {
			if (s[i] >= '0' && s[i] <= '9') {
				t = t * 10 + s[i] - '0';
				//cout << t << ':';
			}
			else {
				if (ans.empty())ans.push_back(t);
				else {
					if (fu == '+')ans[0] = ans[0] + t;
					else ans[0] = ans[0] - t;
				}
				fu = s[i];
				t = 0;
			}
		}
		cout << ans[0] << endl;
	}
	return 0;
}

标签:std,main,string,求职,void,加减,int,字符串,include
来源: https://www.cnblogs.com/zupernova/p/15574204.html