結果

問題 No.49 算数の宿題
ユーザー kichirb3kichirb3
提出日時 2018-03-09 23:46:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 794 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 10,728 KB
実行使用メモリ 8,688 KB
最終ジャッジ日時 2023-08-24 17:38:47
合計ジャッジ時間 861 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,576 KB
testcase_01 AC 18 ms
8,572 KB
testcase_02 AC 18 ms
8,648 KB
testcase_03 AC 20 ms
8,684 KB
testcase_04 AC 19 ms
8,688 KB
testcase_05 AC 20 ms
8,436 KB
testcase_06 AC 18 ms
8,600 KB
testcase_07 AC 18 ms
8,596 KB
testcase_08 AC 18 ms
8,436 KB
testcase_09 AC 18 ms
8,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.49 算数の宿題
https://yukicoder.me/problems/no/49

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def separate_string(S):
    numbers = []
    ops = []

    q = ''
    for s in S:
        if s != '+' and s != '*':
            q += s
        else:
            ops.append(s)
            numbers.append(int(q))
            q = ''
    numbers.append(int(q))
    return numbers, ops


def solve(S):
    numbers, ops = separate_string(S)
    ans = numbers[0]

    for n, o in zip(numbers[1:], ops):
        if o == '+':
            ans *= n
        else:
            ans += n
    return ans


def main(args):
    S = input().strip()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
0