結果
問題 | No.222 引き算と足し算 |
ユーザー |
|
提出日時 | 2015-06-05 22:53:02 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 690 bytes |
コンパイル時間 | 614 ms |
コンパイル使用メモリ | 59,376 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-15 21:26:25 |
合計ジャッジ時間 | 1,610 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:24:17: warning: ‘opnum’ may be used uninitialized in this function [-Wmaybe-uninitialized] 24 | op = str[opnum]; | ^
ソースコード
#include <iostream> #include <cstdlib> using namespace std; int conv(string str){ int result, n = str.size(); if(str[0] == '+') return stoi(str.substr(1, n - 1)); if(str[0] == '-') return stoi(str.substr(1, n - 1)) * (-1); return stoi(str); } int main(){ string xx, yy, op, str; int opnum, xnum, ynum; cin >> str; for(int i = 1; i < str.size(); i++){ if(str[i] == '+' || str[i] == '-'){ opnum = i; break; } } op = str[opnum]; xx = str.substr(0, opnum); yy = str.substr(opnum + 1, str.size() - opnum - 1); xnum = conv(xx); ynum = conv(yy); if(op == "+") cout << xnum - ynum << endl; else cout << xnum + ynum << endl; }