{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"Unfortunately, Peter\u0027s Calculator broke down last week. Now Peter is left with his computer, which has no calculator application, and paper and pencil, which is too tiresome for an engineer. As one of Peter\u0027s friends, you are asked to write him a calculator application. After talking to him, you figure out the following: \r\u003cbr\u003e\u003cul\u003e\r\u003cbr\u003e\u003cli\u003ePeter does only integer arithmetic. The operations he needs are addition, subtraction and multiplication. \r\u003cbr\u003e\u003c/li\u003e\u003cli\u003eHe would like to use an arbitrary number of variables whose names are not longer than 50 characters. \r\u003cbr\u003e\u003c/li\u003e\u003cli\u003eHis main way of doing calculations are to type in a few formulas and to assign them to variables. Some formulas are complicated expressions, which can refer to yet undefined variables, while other formulas consist of a single number. Then Peter asks for the value of some variables, i.e. he evaluates the formulas. \r\u003cbr\u003e\u003c/li\u003e\u003cli\u003ePeters wants to redefine some variables and then to reevaluate formulas that depend on these variables. \r\u003cbr\u003e\u003c/li\u003e\u003c/ul\u003e\r\u003cbr\u003eThe input strictly adheres to the following syntax (given in EBNF): \r\u003cbr\u003e\u003cpre\u003e\r\u003cbr\u003efile \u003d line { line } \u003ceof\u003e.\r\u003cbr\u003eline \u003d [ assignment | print | reset ] \u003ccr\u003e.\r\u003cbr\u003eassignment \u003d var \":\u003d\" expression.\r\u003cbr\u003eprint \u003d \"PRINT\" var.\r\u003cbr\u003ereset \u003d \"RESET\".\r\u003cbr\u003eexpression \u003d term { addop term }.\r\u003cbr\u003eterm \u003d factor { mulop factor }.\r\u003cbr\u003efactor \u003d \"(\" expression \")\" | var | number.\r\u003cbr\u003eaddop \u003d \"+\" | \"-\".\r\u003cbr\u003emulop \u003d \"*\". \u003c/cr\u003e\u003c/eof\u003e\u003c/pre\u003e\r\u003cbr\u003e\r\u003cbr\u003e\r\u003cbr\u003eIn the Extended Backus-Naur Formalism (EBNF), A \u003d B C declares that the grammatical construct A consists of a B followed by a C. A \u003d B | C means that A consists of a B or, alternatively, of a C. A \u003d [ B ] defines construct A to be either a B or nothing and A \u003d { B } tells you that A consists of the concatenation of any number of Bs (including none).\r\u003cbr\u003e\r\u003cbr\u003eThe production var stands for the name of a variable, which starts with a letter followed by up to 49 letters or digits. Letters may be uppercase or lowercase. The production number stands for a integer number. The precise syntax for these productions are given below. The case of letters is important for both variables and statements. \r\u003cbr\u003e\u003cpre\u003e\r\u003cbr\u003evar \u003d letter { letter | digit }.\r\u003cbr\u003enumber \u003d [ \"-\" ] digit { digit }.\r\u003cbr\u003eletter \u003d \"A\" | \"B\" | ... | \"Z\" | \"a\" | \"b\" | ... | \"z\".\r\u003cbr\u003edigit \u003d \"0\" | \"1\" | ... | \"8\" | \"9\".\u003c/pre\u003e\r\u003cbr\u003e\r\u003cbr\u003e\r\u003cbr\u003eBetween the parts of a grammatical construct but not within the names of variables or integer numbers, any number of spaces may appear. \u003ceof\u003e stands for the end of the input file and \u003ccr\u003e stands for the new-line character. All lines in the input file are shorter than 200 characters.\r\u003cbr\u003e\r\u003cbr\u003eThe value of a variable is said to be undefined: \r\u003cbr\u003e\u003cul\u003e\r\u003cbr\u003e\u003cli\u003eif it has not yet been defined or it refers to a variable, which has not yet been defined; \r\u003cbr\u003e\u003c/li\u003e\u003cli\u003eif the definition of the variable contains a cycle. \r\u003cbr\u003e\u003c/li\u003e\u003c/ul\u003e\r\u003cbr\u003eYour are to write a program that implements Peter\u0027s calculator. It should store all variable definitions and for each \"PRINT\" statement evaluate the specified variable based on the latest variable definitions. If your program encounters a \"RESET\" statement, it should delete all stored variables so that all variables become undefined. \r\u003cbr\u003e\r\u003cbr\u003e\u003c/cr\u003e\u003c/eof\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The input contains calculations adhering to the syntax given above. Each line contains either an assignment to a variable, a \"PRINT\" statement, a \"RESET\" statement or nothing. "}},{"title":"Output","value":{"format":"HTML","content":"For each \"PRINT\" statement found in the input, your program should output a line containing the numerical value of the specified variable or the word \"UNDEF\" if the variable is undefined. "}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003ea :\u003d b + c\r\nb :\u003d 3\r\nc :\u003d 5\r\nPRINT d\r\nPRINT a\r\nb :\u003d 8\r\nPRINT a\r\nRESET\r\nPRINT a\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eUNDEF\r\n8\r\n13\r\nUNDEF\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}