## CCC '10 J3 - Punchy

View as PDF

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### Canadian Computing Competition: 2010 Stage 1, Junior #3

In the early days of computing, instructions had to be "punched" onto rectangular cards, one instruction per card. This card deck was then fed into a card reader so the program could be read and executed. Students put elastic bands around their card deck, and, often, carried their cards in a box for fear that they would become rearranged, and thus, their program would be incorrect.

Poor Bill though... he left his cards right near a window and the wind blew his neat deck of cards all over the place, and thus his program is out of order! Bill decides to pick up the cards in some random order and then execute the program.

Write a program to read and execute the commands in Bill's "new" program.

#### Input Specification

The programming language that Bill is using has only two variables ( and ) and seven different types of instructions.

Initially, the variables and contain the value .

There is one instruction per line. An instruction is an integer in the range , possibly followed by a variable name, which in turn is possibly followed by either a number or a variable.

In all instructions below, the variable or may refer to either or . The specific instructions are:

• 1 X n means set the variable to the integer value ;
• 2 X means output the value of variable to the screen;
• 3 X Y means calculate and store the value in variable ;
• 4 X Y means calculate and store the value in variable ;
• 5 X Y means calculate and store the value in variable ;
• 6 X Y means calculate the quotient of and store the value in variable as an integer, discarding the remainder.
• 7 means stop execution of this program.

You may assume that all division instructions do not cause a division by zero, and that all other operations (including instruction 1) do not cause the computed/stored value to be larger than or smaller than .

(To clarify division of negative numbers, and both have quotient and has quotient .)

#### Output Specification

Your program should output the value of the indicated variables, one integer per line, until the "stop" instruction has been read in, at which time your program should stop execution.

#### Sample Input

1 A 3
1 B 4
2 B
2 A
3 A B
2 A
5 A A
2 A
2 B
7

#### Sample Output

4
3
7
0
4

• commented on May 9, 2020, 9:02 p.m.

bruh why test case 5 not working

• commented on Feb. 2, 2020, 4:55 p.m. edited

This comment is hidden due to too much negative feedback. Click here to view it.

• commented on Dec. 30, 2018, 4:58 p.m.

Can someone tell me what's wrong with my code? Thanks for your help.

• commented on Dec. 30, 2018, 8:13 p.m.

Notice that X and Y can refer to both A and A or B and B. I suggest you re-look the parts in your code when X and Y are both A's. Also be careful that A/B ≠ B/A.

• commented on Dec. 30, 2018, 9:38 p.m.

Thanks for your response, @JustinXu, but I'm already aware of this, and my code considers this as it functions.