結果
| 問題 |
No.222 引き算と足し算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-04 04:22:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 465 bytes |
| コンパイル時間 | 1,707 ms |
| コンパイル使用メモリ | 167,300 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-14 00:25:40 |
| 合計ジャッジ時間 | 2,830 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:18:13: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
18 | cout << ans << endl;
| ^~~
main.cpp:8:9: note: 'ans' was declared here
8 | int ans;
| ^~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
string s;
cin >> s;
int ans;
for(int i = 1; i < s.size(); i++){
if(s[i] == '+'){
ans = stoi(s.substr(0, i)) - stoi(s.substr(i + 1, s.size() - (i + 1)));
break;
}else if(s[i] == '-'){
ans = stoi(s.substr(0, i)) + stoi(s.substr(i + 1, s.size() - (i + 1)));
break;
}
}
cout << ans << endl;
}