結果

問題 No.193 筒の数式
ユーザー fiord
提出日時 2015-04-26 23:33:33
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,351 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 60,604 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-05 02:29:42
合計ジャッジ時間 1,524 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main(){
	string s;	cin>>s;

	int be=0,af=0;
	for(int i=(int)s.size()-1;i>=0;i--){
		if(s[i]=='+'||s[i]=='-')	break;
		else af++;

	}
	string move(s.end()-af+1,s.end());
	s.erase(s.end()-af+1,s.end());
	s.insert(0,move);
	long long int temp,cal[2];
	bool pm=true;//true=+,false=-;
	temp=0;	cal[0]=0;	cal[1]=0;
	for(int i=0;i<(int)s.size();i++){
		if(s[i]=='+'){
			if(pm)	cal[0]+=temp;
			else 	cal[0]-=temp;
			pm=true;	temp=0;
		}
		else if(s[i]=='-'){
			if(pm)	cal[0]+=temp;
			else 	cal[0]-=temp;
			pm=false;	temp=0;
		}
		else{
			temp=temp*10+atoi(&s[i]);
			while(s[i]!='+'&&s[i]!='-'&&i<(int)s.size())	i++;
			i--;
		}
	}
	if(pm)	cal[0]+=temp;
	else 	cal[0]-=temp;

	for(int i=0;i<(int)s.size();i++){
		if(s[i]=='+'||s[i]=='-')	break;
		else 	be++;
	}
	move.clear();
	move.assign(s.begin(),s.begin()+be-1);
	s.erase(s.begin(),s.begin()+be-1);
	s+=move;
	pm=true;	temp=0;
	for(int i=0;i<(int)s.size();i++){
		if(s[i]=='+'){
			if(pm)	cal[1]+=temp;
			else 	cal[1]-=temp;
			pm=true;	temp=0;
		}
		else if(s[i]=='-'){
			if(pm)	cal[1]+=temp;
			else 	cal[1]-=temp;
			pm=false;	temp=0;
		}
		else{
			temp=temp*10+atoi(&s[i]);
			while(s[i]!='+'&&s[i]!='-'&&i<(int)s.size())	i++;
			i--;
		}
	}
	cout<<max(cal[0],cal[1])<<endl;
	return 0;
}
0