Skip to content

Instantly share code, notes, and snippets.

@pelly-ryu
Forked from fukkong/kyu-9012.go
Last active September 9, 2019 17:25
Show Gist options
  • Save pelly-ryu/11f7e5ad8679e74db5025dd364248983 to your computer and use it in GitHub Desktop.
Save pelly-ryu/11f7e5ad8679e74db5025dd364248983 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
var n int
reader := bufio.NewReader(os.Stdin)
fmt.Fscanln(reader, &n)
var line []byte
for i := 0; i < n; i++ {
stack := stack([]byte{})
line,_,_ = reader.ReadLine()
isVPS:=true
for k:=0;k<len(line);k++{
if line[k]==40{
stack.push(line[k])
continue
}
if stack.isEmpty() {
isVPS =false
break
}
stack.pop()
}
if isVPS && stack.isEmpty() {
fmt.Println("YES")
}else{
fmt.Println("NO")
}
}
}
type stack []byte
func (s *stack) push(b byte) {
*s = append(*s, b)
}
func (s *stack) pop() {
l := len(*s)
//n := (*s)[l-1]
*s = (*s)[:l-1]
}
func (s stack) top() byte {
return s[len(s)-1]
}
func (s stack) isEmpty() int {
if len(s) == 0 {
return 1
} else {
return 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment