抽象做法80pts求助
查看原帖
抽象做法80pts求助
1287433
__ycy1124__楼主2024/10/21 18:38
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	while(getline(cin,s)){
		bool bj=0,cnt=0;
		long long ans=0,x=0,f=1;
		for(auto it:s){
			if(it=='-'){
				ans+=x*f;
				if(!cnt)
					f=-1;
				x=0;
				cnt=0;
			}
			else if(it>='0'&&it<='9'){
				x=x*10+(it^'0');
				bj=1;
				cnt=1;
			}
			else{
//				cout<<x<<' '<<f<<'\n';
				ans+=x*f;
				x=0; 
				f=1;
				cnt=0;
			}
		}
		if(cnt)
			ans+=x*f;
		if(bj){
			cout<<ans<<'\n';
		}
	}
	return 0;
}
2024/10/21 18:38
加载中...