ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/1802
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var t int
fmt.Fscanln(reader, &t)
for i := 0; i < t; i++ {
input, _ := reader.ReadString('\n')
rules := strings.Split(strings.Replace(input, "\n", "", 1), "")
if check(rules) {
fmt.Fprintln(writer, "YES")
} else {
fmt.Fprintln(writer, "NO")
}
}
}
func check(rules []string) bool {
if len(rules) == 1 {
return true
}
for i := 0; i < len(rules)/2; i++ {
if rules[i] == rules[len(rules)-1-i] { // ๊ฐ์ด๋ฐ๋ฅผ ๊ธฐ์ค์ผ๋ก ์ ํ๋ ๋ถ๋ถ์ ์๋ก ๋ค๋ฅธ ๊ฐ์ด์ด์ผ ํจ
return false
}
}
return check(rules[0:len(rules)/2]) && check(rules[len(rules)/2+1:len(rules)]) // ๊ฐ์ด๋ฐ๋ฅผ ๊ธฐ์ค์ผ๋ก ์ผ์ชฝ๊ณผ ์ค๋ฅธ์ชฝ์ ์ฒดํฌ
}
๐จ Python3
# https://www.acmicpc.net/problem/1802
import sys
def check(rules):
if len(rules) == 1:
return True
for i in range(len(rules)//2):
if rules[i] == rules[len(rules)-1-i]:
return False
return check(rules[0:len(rules)//2]) and check(rules[len(rules)//2+1:len(rules)])
if __name__ == "__main__":
t = int(sys.stdin.readline())
for i in range(t):
rules = list(sys.stdin.readline().rstrip())
if check(rules):
print("YES")
else:
print("NO")
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 1049๋ฒ / ๊ธฐํ์ค [Go][Python3] (0) | 2021.02.19 |
---|---|
BOJ / 15815๋ฒ / ์ฒ์ฌ ์ํ์ ์ฑํ [Go][Python3] (0) | 2021.02.18 |
BOJ / 2428๋ฒ / ํ์ [Go][Python3] (0) | 2021.02.16 |
BOJ / 10546๋ฒ / ๋ฐฐ๋ถ๋ฅธ ๋ง๋ผํ ๋ [Go][Python3] (0) | 2021.02.15 |
BOJ / 2910๋ฒ / ๋น๋ ์ ๋ ฌ [Go][Python3] (0) | 2021.02.14 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ์๊ณ ๋ฆฌ์ฆ
- ๋ฐ๋
- ballet
- BFS
- baekjoon
- python3
- MongoDB
- ๋ฐฑ์ค
- ์ด๋ถํ์
- java
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ์คํ
- ์๊ฐ๊ต์ฒด
- Golang
- ๋ธ๋ฃจํธํฌ์ค
- go
- dp
- ํ
- ๋งฅ๋ถํ๋ก
- ๋งฅ๋ถ
- ๋ถํ ์ ๋ณต
- BOJ
- dfs
- ํ๋ก์ด๋์์ฌ
- ๋ชฝ๊ณ ๋๋น
- Algorithm
- Macbook pro 2012 mid 13
- ์๋ฐ
- ํด์๋งต
- AWS
- Total
- Today
- Yesterday