結果
問題 | No.193 筒の数式 |
ユーザー |
![]() |
提出日時 | 2015-10-29 22:10:42 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 913 bytes |
コンパイル時間 | 648 ms |
コンパイル使用メモリ | 70,128 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-13 04:39:34 |
合計ジャッジ時間 | 1,325 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include<iostream> #include<string> #include<queue> #include<algorithm> int solve(std::string s) { std::queue<std::string> q; int num = 0; for (int i = 0; i < s.length(); i++) { if (!isdigit(s[i])) { if (i == 0 || i == s.length() - 1 || !isdigit(s[i + 1])) return -999999; q.push(std::to_string(num)); q.push(std::to_string(s[i])); num = 0; } else num = num * 10 + (s[i] - '0'); } q.push(std::to_string(num)); num = std::stoi(q.front());q.pop(); while (q.size()) { std::string d = q.front();q.pop(); if (d == "43") num += std::stoi(q.front()); else num -= std::stoi(q.front()); q.pop(); } return num; } int main() { std::string str; std::cin >> str; int max = -9999; for (int i = 0; i < str.length(); i++) { max = std::max(solve(str), max); char s = str.back(); str.erase(str.end() - 1); str.insert(str.begin(), s); } std::cout << max << std::endl; return 0; }