-
-
Save pelly-ryu/11f7e5ad8679e74db5025dd364248983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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