結果

問題 No.193 筒の数式
ユーザー aaaaaaiuaaaaaaiu
提出日時 2019-08-08 13:22:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 791 bytes
コンパイル時間 1,866 ms
コンパイル使用メモリ 195,728 KB
最終ジャッジ日時 2025-01-07 11:01:02
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin>>s;
    int n=s.size();
    int mx=-100000000;
    for (int i=0;i<n;i++) {
        string t=s.substr(i)+s.substr(0,i);
        if (!isdigit(t[0])) continue;
        int ans=0;
        int j=0;
        while (j<n && isdigit(t[j])) {
            ans=10*ans+t[j]-'0';
            j++;
        }
        while (j < n) {
            int sign=1;
            if (t[j]=='-') sign=-1;
            j++;
            if (j==n) goto invalid;
            int num=0;
            while (j<n && isdigit(t[j])) {
                num=10*num+t[j]-'0';
                j++;
            }
            ans+=num*sign;
        }
        mx=max(mx,ans);
        invalid:;
    }
    cout<<mx<<endl;
    return 0;
}
0