結果

問題 No.222 引き算と足し算
ユーザー MayimgMayimg
提出日時 2018-11-26 10:19:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 726 bytes
コンパイル時間 1,465 ms
コンパイル使用メモリ 166,172 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 12:56:49
合計ジャッジ時間 4,136 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 RE -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 RE -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 RE -
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 RE -
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 RE -
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 RE -
testcase_21 AC 1 ms
4,376 KB
testcase_22 RE -
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 RE -
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 RE -
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 RE -
権限があれば一括ダウンロードができます

ソースコード

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