結果

問題 No.222 引き算と足し算
ユーザー zaichu
提出日時 2016-01-20 23:38:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 539 bytes
コンパイル時間 1,377 ms
コンパイル使用メモリ 158,804 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-15 22:09:09
合計ジャッジ時間 2,350 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
	string s;
	cin >> s;
	int math = 1;
	int mid = s.size() / 2;
	int a = 0, b = 0;
	for(int i = mid - 1; i >= 0; i--){
		if(s[i] == '-')	a *= -1;
		else if(s[i] == '+') continue;
		else a += int(s[i] - '0') * math;
		math *= 10;
	}
	math = 1;
	for(int i = s.size() - 1; i > mid; i--){
		if(s[i] == '-')	b *= -1;
		else if(s[i] == '+') continue;
		else b += int(s[i] - '0') * math;
		math *= 10;
	}
	if(s[mid] == '+') cout << a - b << endl;
	else cout << a + b << endl;
	return 0;
}
0