結果

問題 No.222 引き算と足し算
ユーザー Mayimg
提出日時 2018-11-26 10:19:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 726 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 167,024 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-29 12:20:21
合計ジャッジ時間 4,116 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 RE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s; cin >> s;
	bool minus1 = false, minus2 = false;
	int i = 0;
	if(s[i] == '-') {
		i++;
		minus1 = true;
	}
	bool add = true;
	string tmp1, tmp2;
	while(s[i] != '+' && s[i] != '-'){
		tmp1 += s[i];
		i++;
	}
	if(s[i] == '+') {
		add = false;
	}
	i++;
	if(s[i] == '-') {
		minus2 = true;
		i++;
	}
	while(i < s.size()) {
		tmp2 += s[i];
		i++;
	}
	int a = stoi(tmp1), b = stoi(tmp2);
	if(minus1){
		a = -1 * a;
	}
	if(minus2){
		b = -1 * b;
	}
	if(add) cout << a + b << endl;
	else cout << a - b << endl;
	
	return 0;                                              
}
	
0