結果

問題 No.222 引き算と足し算
コンテスト
ユーザー hanorver
提出日時 2015-10-08 20:15:29
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 419 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 432 ms
コンパイル使用メモリ 72,192 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-10 23:26:27
合計ジャッジ時間 1,739 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:24:22: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   24 |         std::cout << ans << std::endl;
      |                      ^~~
main.cpp:10:13: note: 'ans' was declared here
   10 |         int ans;
      |             ^~~

ソースコード

diff #
raw source code

#include<iostream>
#include<string>

int main() {
	std::string str;
	std::cin >> str;

	char op;
	int op_iter;
	int ans;
	for (int i = 1; i < str.length(); i++) {
		if (str[i] < '0') {
			int a = std::stoi(str.substr(0, i));
			int b = std::stoi(str.substr(i + 1, str.size() - i));
			if (str[i] == '+') {
				ans = a - b;
			} else {
				ans = a + b;
			}
			break;
		}
	}

	std::cout << ans << std::endl;
	return 0;
}
0