Contrary to popular belief, the fish in the ocean are also expert programmers. They use a language called Fish++, which is unfortunately limited in functionality. The current version of Fish++ only supports 3 variables, and all Fish++ programs will always have exactly 3 at all times. For simplicity, they are called a
, b
, and c
. These variables initially are integers, initially all at . Since the fish are simple-minded, the only mathematical operations they can perform is addition of these integers. The latest version of Fish++ introduced strings, however they too are quite limited. Each variable can either be an integer or a string. All integers will always be positive, and all variable assignments will always match their current type. All strings will be lowercase letters, have no spaces, not have quotations, and not be
a
, b
, or c
to avoid ambiguity.
Each line of a Fish++ program will have a single operation, and always end with a single semicolon separated by a space. Each line will be in one of the following formats:
x = y + z
the variablex
will be reassigned to the sum ofy
andz
, wherey
andz
may be either positive integers or another integer variable that is notx
fish.print x
output the value ofx
(which may be an integer or string)x = y
the variablex
will be changed to the value ofy
convert x -> y -> z
the variablex
will be converted to typey
(which will either beinteger
orstring
) and have a value ofz
.abyss end
the end of the program has been reached
To ensure the fish console is accessed properly, the first line will always be the line include fish.io
. If it is not, and the program attempts to access the fish.print
method, an error message is the only thing that should be outputted that should read Exception in program: no such method "fish.print" is found
.
Your task is to interpret and run a Fish++ program. There will never be more than lines in any Fish++ program, and no integer will surpass
. Each program will call the
fish.print
method at least once. You may assume that each program is a valid Fish++ program according to the rules above, without any additional errors.
Input Specifications
Each line will be one of the above operations as described above. The operation abyss end
will only be called once to indicate the end of the program.
Output Specifications
For each operation fish.print x
, output the value of x
. If include fish.io
was not included as the first line, and the operation fish.print x
is called, then output the error message once and finish the program.
Subtasks
Subtask 1 [50%]
The convert
operation will never be called and there will be no strings.
Subtask 2 [50%]
No additional constraints
Sample Input 1
include fish.io ;
fish.print a ;
a = 3 ;
fish.print a ;
b = a + 5 ;
fish.print b ;
fish.print a ;
abyss end ;
Sample Output 1
0
3
8
3
Explanation for Sample Output 1
The first line allows for the use of the fish.print
method without any errors. The second line outputs the value of a
, and since all variables default to integers with the value of
, its default value of
is outputted. The third line reassigns the variable
a
to . The fourth line outputs the value of
a
, which is now . The fifth line reassigns the variable
b
to the value of a
plus , which is
. The sixth and seventh lines output the values of
b
and a
respectively. The eighth line ends the program.
This program would satisfy the constraints of the first subtask.
Sample Input 2
include fish.io ;
a = 5 ;
fish.print a ;
convert a -> string -> hello ;
a = goodbye ;
fish.print a ;
c = 6 ;
convert a -> integer -> 9 ;
a = c + 5 ;
fish.print a ;
convert c -> integer -> 3 ;
fish.print c ;
fish.print string ;
abyss end ;
Sample Output 2
5
goodbye
11
3
string
Explanation for Sample Output 2
Notice that it is possible to convert a variable to the same type but reassign it to a different value using the convert
function. Also, recall that strings don't have quotations.
Sample Input 3
fish.print ocean ;
fish.print goodbye ;
abyss end ;
Sample Output 3
Exception in program: no such method "fish.print" is found
Explanation for Sample Output 3
Since include fish.io
was not the first line of the program but the fish.print
method was called, the error message is the only thing that should be outputted.
Hint: To reduce the amount of code, consider storing the variables as strings and putting reused code into a function. It is possible to handle each line extremely concisely, however how much you choose to write is up to you.
Comments