結果
| 問題 | No.222 引き算と足し算 |
| コンテスト | |
| ユーザー |
hanorver
|
| 提出日時 | 2015-10-08 20:09:08 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 518 bytes |
| 記録 | |
| コンパイル時間 | 524 ms |
| コンパイル使用メモリ | 71,920 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-10 23:26:16 |
| 合計ジャッジ時間 | 1,721 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:24:9: warning: 'op' may be used uninitialized [-Wmaybe-uninitialized]
24 | if (op == '+') {
| ^~
main.cpp:8:14: note: 'op' was declared here
8 | char op;
| ^~
main.cpp:18:37: warning: 'op_iter' may be used uninitialized [-Wmaybe-uninitialized]
18 | int a = std::stoi(str.substr(0, op_iter));
| ~~~~~~~~~~^~~~~~~~~~~~
main.cpp:9:13: note: 'op_iter' was declared here
9 | int op_iter;
| ^~~~~~~
ソースコード
#include<iostream>
#include<string>
int main() {
std::string str;
std::cin >> str;
char op;
int op_iter;
for (int i = 1; i < str.length(); i++) {
if (str[i] < '0') {
op = str[i];
op_iter = i;
break;
}
}
int a = std::stoi(str.substr(0, op_iter));
int b = std::stoi(str.substr(op_iter + 1, str.size() - op_iter));
int ans;
//アリスは足し算と引き算を逆に認識している
if (op == '+') {
ans = a - b;
} else {
ans = a + b;
}
std::cout << ans << std::endl;
return 0;
}
hanorver