結果
問題 | No.49 算数の宿題 |
ユーザー |
![]() |
提出日時 | 2016-02-26 15:10:34 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 32 ms / 5,000 ms |
コード長 | 735 bytes |
コンパイル時間 | 159 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,624 KB |
最終ジャッジ日時 | 2024-12-23 01:48:47 |
合計ジャッジ時間 | 1,054 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import collections import itertools def calc(equation): is_operator = lambda x: x in "+*" operators = collections.deque() operands = collections.deque() for key, group in itertools.groupby(equation, is_operator): if key: operators.append("*" if "".join(group) == "+" else "+") else: operands.append(int("".join(group))) value = operands.popleft() while operators and operands: operand = operands.popleft() if operators.popleft() == "+": value += operand else: value *= operand return value def main(): print(calc(input())) if __name__ == '__main__': main()