You get 10 integers by the input, separated by whitespace. You need to print out only even numbers. Numbers must be printed in reversed order, each number in a new line. Use a Stack structure to solve this task.
Using stack in Go
Even stack
Report a typo
Sample Input 1:
1 2 3 4 5 6 7 8 9 0Sample Output 1:
0
8
6
4
2Write a program in Go
package main
import (
"errors"
"fmt"
)
func main() {
// the Stack struct is hidden but already declared
var evenStack ?
var num int
for i := 0; i < 10; i++ {
fmt.Scan(&num)
if num%2 == 0 {
evenStack.?(num)
}
}
?, ? := evenStack.Pop()
for ? == nil {
fmt.Println(val)
val, err = evenStack.?()
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.