結果

問題 No.222 引き算と足し算
ユーザー springrollspringroll
提出日時 2018-11-18 17:44:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,134 bytes
コンパイル時間 1,488 ms
コンパイル使用メモリ 166,628 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 01:55:12
合計ジャッジ時間 3,305 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:71:9: 警告: ‘op’ may be used uninitialized [-Wmaybe-uninitialized]
   71 |         if (op == '+') {
      |         ^~
main.cpp:9:14: 備考: ‘op’ はここで定義されています
    9 |         char op;
      |              ^~

ソースコード

diff #

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


int main() {
	string s;
	cin >> s;
	int x,y;
	char op;
	int i=0;

	bool fx=false, fy=false, f=false;
	
	/* x と op を求める処理 */
	if (s[0] == '+' || s[0] == '-' ) {
		string sx;
		for (i = 1; i < s.length(); i++) {
			if (s[i] == '+' || s[i] == '-' ) {
				op = s[i];
				break;
			}
			else {
				sx.push_back(s[i]);
			}
		}
		if (s[0] == '+') {
			x = stoi(sx);
		}
		else {
			x = stoi(sx);
			x *= -1;
		}
	}
	else {
		string sx;
		for (i = 0; i < s.length(); i++) {
			if (s[i] == '+' || s[i] == '-') {
				op = s[i];
				break;
			}
			else {
				sx.push_back(s[i]);
			}
		}
		x = stoi(sx);
	}

	/* y を求める処理 */
	if (s[i+1] == '+' || s[i+1] == '-') {
		string sy;
		for (int j = i+2; j < s.length(); j++) {
			sy.push_back(s[j]);
		}
		if (s[i+1] == '+') {
			y = stoi(sy);
		}
		else {
			y = stoi(sy);
			y *= -1;
		}
	}
	else {
		string sy;
		for (int j = i + 1; j < s.length(); j++) {
			sy.push_back(s[j]);
		}
		y = stoi(sy);
	}

	//cout << x <<" "<< op <<" "<< y << endl;
	if (op == '+') {
		cout << x-y << endl;
	}
	else {
		cout << x+y << endl;
	}
}
0