115. Pseudocode Compiler

Codeforces
IDCF10269115
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
In this question your goal is to make a program that will simulate running some pretty basic pseudocode. Here is the syntax that will be used: Defining a variable: -"var variableName = value" -value can be any integer -value can be a simple math equations ex: "3 + 5" -value can be a simple math equation that includes a variable "testVar + 2" Manipulating a variable: -"variableName = value" -same rules applied to what the value can be as the one above -Ex: "test1 = test1 + 2 - test2" Printing: -"print (hello word )+exampleVariable+" -text that is being printed will be surrounded in parentheses -variables being printed will be surrounded in addition signs The first line will be the number of lines of code. The next X number of lines will be the code that you need to simulate. Print whatever the program prints. ## Input The first line will be the number of lines of code. The next X number of lines will be the code that you need to simulate. ## Output Print whatever the program prints. [samples]
**Definitions** Let $ n \in \mathbb{Z} $ be the number of code lines. Let $ \mathcal{V} $ be a finite map from variable names to integer values, initially empty. **Syntax Rules** 1. **Variable Definition**: - Format: `var x = e` - $ e $ is an arithmetic expression over integers and existing variables in $ \mathcal{V} $. - Evaluate $ e $ to integer $ v $, then set $ \mathcal{V}[x] \leftarrow v $. 2. **Variable Assignment**: - Format: `x = e` - Same evaluation rules as above; update $ \mathcal{V}[x] \leftarrow \text{eval}(e) $. 3. **Print Statement**: - Format: `print (s_0) + x_1 + (s_1) + x_2 + \dots + (s_k)` - $ s_i \in \mathbb{S} $ are string literals (without quotes), $ x_j \in \text{dom}(\mathcal{V}) $ are variable names. - Output: Concatenation of $ s_0 $, $ \mathcal{V}[x_1] $, $ s_1 $, $ \mathcal{V}[x_2] $, ..., $ s_k $, with each $ \mathcal{V}[x_j] $ converted to its decimal string representation. **Constraints** - All expressions $ e $ are well-formed arithmetic expressions using `+`, `-`, integers, and variables in $ \mathcal{V} $. - All variables in expressions are defined before use. - All print statements follow the exact format with parentheses and `+` delimiters. **Objective** Simulate the $ n $ lines of code in order. For each print statement, output the resulting concatenated string.
API Response (JSON)
{
  "problem": {
    "name": "115. Pseudocode Compiler",
    "description": {
      "content": "In this question your goal is to make a program that will simulate running some pretty basic pseudocode. Here is the syntax that will be used: Defining a variable: -\"var variableName = value\" -value ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269115"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "In this question your goal is to make a program that will simulate running some pretty basic pseudocode. Here is the syntax that will be used:\n\nDefining a variable: -\"var variableName = value\" -value ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of code lines.  \nLet $ \\mathcal{V} $ be a finite map from variable names to integer values, initially empty.  \n\n**Syntax Rules**  \n1. **Variabl...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments