Untitled

 avatar
user_0361084808
plain_text
2 years ago
1.7 kB
1
Indexable
Never
from collections import deque

n, m = map(int,input().split())
all_cell_id = deque()
for i in range(n):
    all_cell_id.append([])

for _ in range(m):
    L = []
    formula = list(input().split())
    L.append(formula[0])
    int_formula = list(map(lambda x : int(x), formula[1:]))
    all_formula = L + int_formula

    if formula[0] == 'A':
        eng_letter, cell_id, num = all_formula
        all_cell_id[cell_id-1].append(num)
        print(num)
    elif formula[0] == 'B':
        eng_letter, cell_id, cell_1, num = all_formula
        try:
            cell_1_val = all_cell_id[cell_1-1][0]
            all_cell_id[cell_id-1].append(cell_1_val + num)
            print(cell_1_val + num)
        except IndexError:
            print('#REF!')
    elif formula[0] == 'C':
        eng_letter, cell_id, cell_1, cell_2, num = all_formula
        try:
            cell_1_val = all_cell_id[cell_1-1][0]
            cell_2_val = all_cell_id[cell_2-1][0]
            all_cell_id[cell_id-1].append(cell_1_val + cell_2_val + num)
            print(cell_1_val + cell_2_val + num)
        except IndexError:
            print('#REF!')
    elif formula[0] == 'D':
        eng_letter, cell_id, cell_1, cell_2, cell_3, num = all_formula
        try:
            cell_1_val = all_cell_id[cell_1-1][0]
            cell_2_val = all_cell_id[cell_2-1][0]
            cell_3_val = all_cell_id[cell_3-1][0]
            all_cell_id[cell_id-1].append(cell_1_val + cell_2_val + cell_3_val + num)
            print(cell_1_val + cell_2_val + cell_3_val + num)
        except IndexError:
            print('#REF!')
    
for i in range(m, n):
    all_cell_id[i].append(0)
    print(all_cell_id[i][0])