結果
問題 |
No.222 引き算と足し算
|
ユーザー |
![]() |
提出日時 | 2015-10-08 20:09:08 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 518 bytes |
コンパイル時間 | 474 ms |
コンパイル使用メモリ | 57,244 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-15 22:05:26 |
合計ジャッジ時間 | 1,358 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:18:37: warning: ‘op_iter’ may be used uninitialized in this function [-Wmaybe-uninitialized] 18 | int a = std::stoi(str.substr(0, op_iter)); | ~~~~~~~~~~^~~~~~~~~~~~ main.cpp:24:9: warning: ‘op’ may be used uninitialized in this function [-Wmaybe-uninitialized] 24 | if (op == '+') { | ^~
ソースコード
#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; }