아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Cells

시간 제한1초메모리 제한1024 MB

요약
셀 참조가 있는 스프레드시트 수식을 계산하고 의존 순서를 처리한 뒤 셀 이름 알파벳 순으로 결과를 출력한다.
난이도

보통10점 중 5점

유형
그래프, DFS, 위상 정렬, 문자열
정답자
아직 제출이 없습니다

문제

Tim loves spreadsheets. Everything he does on a computer, he does in a spreadsheet. Track his expenses? Create a spreadsheet! Decide which car to buy? Create a spreadsheet to compare them! Make an inventory of his games? Create a spreadsheet! Decide which girl he loves most? …

Unfortunately his spreadsheet software just crashed and he needs some of the data right now and does not have the time to install a competing office suit.

Given the formulas used in the cells of a spreadsheet, calculate the values of all the cells.

When evaluating an expression, usual priorities apply: first we evaluate all * and / (left to right), and only then all + and - (again, left to right).

You may assume that the expressions are such that when evaluating the expression in correct order, the result and also all intermediate values will fit into 32-bit signed integer variables.

The operator / represents integer division which is always rounded down. The dividend will always be non-negative and the divisor will always be positive.

입력

The first line of the input file contains an integer T specifying the number of test cases. Each test case is preceded by a blank line.

Each test case starts a single number N giving the number of expression. Each of the following N lines contains a single cell formula of the form “CELL = EXPRESSION”, where CELL is the name of the cell and EXPRESSION is a mathematical expression consisting of cell names and the operators +, -, * and /. A cell name is a non-empty sequence of letters followed by a positive integer. The length of cell name is less than or equal to 5.

Each test case is correct: there are no cycles, and all cells referenced in expressions have definitions.

출력

For each test case output the calculated values of cells, one per line, in the form “CELL = VALUE”. The rows in the output should be ordered alphabetically. (To compare two rows, take a look at the first character where they differ. The one with a smaller ASCII value goes first.)

예제1

  1. 예제 1

    입력
    2
    
    3
    A47 = 5 + ZZ22
    ZZ22 = 3
    A9 = 13 + A47 * ZZ22
    
    2
    A1 = 4 / 7 + 4 / 7
    B2 = 3 * 3 / 7
    
    예상 출력
    A47 = 8
    A9 = 37
    ZZ22 = 3
    
    A1 = 0
    B2 = 1