結果
問題 | No.193 筒の数式 |
ユーザー | 古寺いろは |
提出日時 | 2015-04-26 22:08:54 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 851 bytes |
コンパイル時間 | 1,278 ms |
コンパイル使用メモリ | 160,136 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-05 02:52:24 |
合計ジャッジ時間 | 1,936 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include "bits/stdc++.h" using namespace std; long long calc(string s){ long long ans = 0; long long pre = 0; int d = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '+'){ if (d == 0) ans += pre; else ans -= pre; pre = 0; d = 0; } else if (s[i] == '-'){ if (d == 0) ans += pre; else ans -= pre; pre = 0; d = 1; } else{ int t = s[i] - '0'; pre *= 10; pre += t; } } if (d == 0) ans += pre; else ans -= pre; pre = 0; return ans; } int main() { string st; cin >> st; int N = st.size(); long long ans = -99999999; for (int i = 0; i < N; i++) { string s = ""; for (int j = 0; j < N; j++) { s += st[(i + j) % N]; } if (s[0] == '+' || s[0] == '-') continue; if (s[s.size() - 1] == '+' || s[s.size() - 1] == '-') continue; ans = max(ans, calc(s)); } cout << ans << endl; }