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.
68 lines
1.0 KiB
68 lines
1.0 KiB
![]()
5 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"os"
|
||
|
"strconv"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
![]()
4 years ago
|
func deleteExtraSpaces(a []string) (res []string) {
|
||
|
for _, v := range a {
|
||
![]()
5 years ago
|
if v != "" {
|
||
|
res = append(res, v)
|
||
|
}
|
||
|
}
|
||
![]()
4 years ago
|
return
|
||
![]()
5 years ago
|
}
|
||
|
|
||
|
func main() {
|
||
![]()
4 years ago
|
if len(os.Args) != 2 {
|
||
|
fmt.Println("Error")
|
||
|
return
|
||
|
}
|
||
|
var values []int
|
||
|
op := strings.Split(os.Args[1], " ")
|
||
|
op = deleteExtraSpaces(op)
|
||
|
for _, v := range op {
|
||
|
val, err := strconv.Atoi(v)
|
||
![]()
5 years ago
|
|
||
![]()
4 years ago
|
if err == nil {
|
||
|
values = append(values, val)
|
||
|
continue
|
||
|
}
|
||
![]()
5 years ago
|
|
||
![]()
4 years ago
|
n := len(values)
|
||
|
if n < 2 {
|
||
|
fmt.Println("Error")
|
||
|
return
|
||
![]()
5 years ago
|
}
|
||
![]()
4 years ago
|
|
||
|
switch v {
|
||
|
case "+":
|
||
|
values[n-2] += values[n-1]
|
||
|
values = values[:n-1]
|
||
|
case "-":
|
||
|
values[n-2] -= values[n-1]
|
||
|
values = values[:n-1]
|
||
|
case "*":
|
||
|
values[n-2] *= values[n-1]
|
||
|
values = values[:n-1]
|
||
|
case "/":
|
||
|
values[n-2] /= values[n-1]
|
||
|
values = values[:n-1]
|
||
|
case "%":
|
||
|
values[n-2] %= values[n-1]
|
||
|
values = values[:n-1]
|
||
|
default:
|
||
![]()
5 years ago
|
fmt.Println("Error")
|
||
![]()
4 years ago
|
return
|
||
![]()
5 years ago
|
}
|
||
![]()
4 years ago
|
}
|
||
|
if len(values) == 1 {
|
||
|
fmt.Println(values[0])
|
||
![]()
5 years ago
|
} else {
|
||
|
fmt.Println("Error")
|
||
|
}
|
||
|
}
|