mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.2 KiB
1.2 KiB
doop
Instructions
Write a program that is called doop
.
The program has to be used with three arguments:
- A value
- An operator
- Another value
You should use int64
.
The following operators are considered valid: +
, -
, /
, *
, %
.
In case of an invalid operator or overflow the programs prints 0
.
In case of an invalid number of arguments the program prints nothing.
The program has to handle the modulo and division operations by 0 as shown on the output examples below.
Usage
student@ubuntu:~/[[ROOT]]/test$ go build doop.go
student@ubuntu:~/[[ROOT]]/test$ ./doop
student@ubuntu:~/[[ROOT]]/test$ ./doop 1 + 1 | cat -e
2$
student@ubuntu:~/[[ROOT]]/test$ ./doop hello + 1 | cat -e
0$
student@ubuntu:~/[[ROOT]]/test$ ./doop 1 p 1 | cat -e
0$
student@ubuntu:~/[[ROOT]]/test$ ./doop 1 / 0 | cat -e
No division by 0$
student@ubuntu:~/[[ROOT]]/test$ ./doop 1 % 0 | cat -e
No modulo by 0$
student@ubuntu:~/[[ROOT]]/test$ ./doop 9223372036854775807 + 1
0
student@ubuntu:~/[[ROOT]]/test$ ./doop -9223372036854775809 - 3
0
student@ubuntu:~/[[ROOT]]/test$ ./doop 9223372036854775807 "*" 3
0
student@ubuntu:~/[[ROOT]]/test$ ./doop 1 "*" 1
1
student@ubuntu:~/[[ROOT]]/test$ ./doop 1 "*" -1
-1
student@ubuntu:~/[[ROOT]]/test$