結果

問題 No.49 算数の宿題
ユーザー けむけむけむけむ
提出日時 2021-07-22 15:43:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 734 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 7,916 KB
最終ジャッジ日時 2023-08-24 17:50:14
合計ジャッジ時間 904 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,800 KB
testcase_01 AC 16 ms
7,800 KB
testcase_02 AC 17 ms
7,784 KB
testcase_03 AC 16 ms
7,916 KB
testcase_04 AC 16 ms
7,752 KB
testcase_05 AC 16 ms
7,720 KB
testcase_06 AC 16 ms
7,768 KB
testcase_07 AC 16 ms
7,824 KB
testcase_08 AC 16 ms
7,832 KB
testcase_09 AC 16 ms
7,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def keisan(S):
    S = list(S)
    cnvS = []
    m = 0
    s = ''
    for n in range(len(S)):
        if (S[n] == '*') or (S[n] == '+'):
            for i in range(m, n):
                s = s + S[i]
            cnvS.append(int(s))
            cnvS.append(S[n])
            s = ''
            m = n + 1
        elif n == len(S) - 1:
            for i in range(m, n + 1):
                s = s + S[i]
            cnvS.append(int(s))
    j = 0
    ans = cnvS[0]
    while j < len(cnvS) - 2:
        if cnvS[j + 1] == '*':
            ans += cnvS[j + 2]
        elif cnvS[j + 1] == '+':
            ans *= cnvS[j + 2]
        j += 2
    return ans


def main():
    S = input()
    print(keisan(S))

if __name__ == '__main__':
    main()
0