Last active
September 9, 2019 16:56
-
-
Save fukkong/8a660b38bfce9268620e70e00955ef82 to your computer and use it in GitHub Desktop.
This file contains hidden or 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{}) | |
isVPS := true | |
line, _, _ = reader.ReadLine() | |
for k := 0; k < len(line); k++ { | |
if line[k] == 40 { | |
stack.push(line[k]) | |
} else { | |
if stack.isEmpty() == 1 { | |
isVPS = false | |
break | |
} else { | |
stack.pop() | |
} | |
} | |
} | |
if stack.isEmpty() == 1 && isVPS { | |
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