結果

問題 No.222 引き算と足し算
ユーザー hanorver
提出日時 2015-10-08 20:15:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 419 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 57,280 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-15 22:05:28
合計ジャッジ時間 1,392 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:22: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |         std::cout << ans << std::endl;
      |                      ^~~

ソースコード

diff #

#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