結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
izryt(趣味)
|
| 提出日時 | 2016-01-18 02:28:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 440 bytes |
| コンパイル時間 | 1,248 ms |
| コンパイル使用メモリ | 158,940 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-15 22:08:59 |
| 合計ジャッジ時間 | 2,113 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:23: warning: ‘pos_op’ may be used uninitialized in this function [-Wmaybe-uninitialized]
17 | char op = e[pos_op];
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main()
{
string e; cin >> e;
int pos_op;
for (int i = 1; i < e.size(); ++i) {
if (isdigit(e[i - 1]) && !isdigit(e[i])) {
pos_op = i;
break;
}
}
char op = e[pos_op];
string x = e.substr(0, pos_op);
string y = e.substr(pos_op + 1, e.size() - pos_op - 1);
cout << stoi(x) + (op == '+' ? -1 : 1) * stoi(y) << endl;
}
izryt(趣味)