結果

問題 No.193 筒の数式
ユーザー Hachimori
提出日時 2015-04-27 00:25:42
言語 Python2
(2.7.18)
結果
AC  
実行時間 11 ms / 1,000 ms
コード長 769 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2024-07-05 03:18:29
合計ジャッジ時間 1,078 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python
#coding:utf8

def read():
    return raw_input()


def calc(expr):
    ret = 0
    idx = 0
    
    expr = '+' + expr
    while idx < len(expr):
        isAdd = expr[idx] == '+'
        idx += 1

        num = ''
        while idx < len(expr) and expr[idx].isdigit():
             num += expr[idx]
             idx += 1

        if isAdd:
            ret += int(num)
        else:
            ret -= int(num)

    return ret

    
def work(s):
    ans = -(1 << 30)

    for L in range(len(s)):
        expr = s[L:] + s[:L]

        if expr[0]  == '+' or expr[0]  == '-' or \
           expr[-1] == '+' or expr[-1] == '-':
           continue
        
        ans = max(ans, calc(expr))

    print ans


if __name__ == "__main__":
    work(read())
0