ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/2503
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
var games []Game
for i := 0; i < n; i++ {
game := Game{}
fmt.Fscanln(reader, &game.number, &game.strike, &game.ball)
games = append(games, game)
}
var count int // ๊ฐ๋ฅํ ๋ต์ ๊ฐ์
for i := 123; i <= 987; i++ { // ๋ชจ๋ ๊ฒฝ์ฐ ๊ณ์ฐ
var isAnswer bool = true
a, b, c := i/100, (i/10)%10, i%10
if !checkValid(a, b, c) { // ๊ฐ ์๋ฆฟ์๊ฐ 1-9์ ์๋ก ๋ค๋ฅธ ์ซ์ ์ธ๊ฐ๋ก ๊ตฌ์ฑ๋์๋์ง ์ฒดํฌ
continue
}
for j := 0; j < n; j++ { // i๊ฐ์ด ๋ฏผํ์ด์ ์ง๋ฌธ๊ณผ ์์์ ๋๋ต์ ๋ชจ๋ ๊ฒฝ์ฐ์ ๋ํด ์ผ์นํ๋ ๊ฒฝ์ฐ count ์ฆ๊ฐ
strike, ball, number := 0, 0, games[j].number
a2, b2, c2 := number/100, number/10%10, number%10
if a == a2 {
strike++
}
if a == b2 || a == c2 {
ball++
}
if b == b2 {
strike++
}
if b == a2 || b == c2 {
ball++
}
if c == c2 {
strike++
}
if c == a2 || c == b2 {
ball++
}
if !(strike == games[j].strike && ball == games[j].ball) {
isAnswer = false
break
}
}
if isAnswer {
count++
}
}
fmt.Fprintln(writer, count)
}
type Game struct {
number int
strike int
ball int
}
func checkValid(a, b, c int) bool {
if b == 0 || c == 0 {
return false
}
if a == b || b == c || c == a {
return false
}
return true
}
๐จ Python3
# https://www.acmicpc.net/problem/2503
import sys
def check_valid(a, b, c):
if b == 0 or c == 0:
return False
if a == b or b == c or c == a:
return False
return True
if __name__ == "__main__":
n = int(sys.stdin.readline())
games = []
for i in range(n):
games.append(list(map(int, sys.stdin.readline().split())))
count = 0
for i in range(123, 988):
is_answer = True
a, b, c = i//100, (i//10)%10, i%10
if not check_valid(a, b, c):
continue
for j in range(0, n):
strike, ball, number = 0, 0, games[j][0]
a2, b2, c2 = number//100, number//10%10, number%10
if a == a2:
strike += 1
if a == b2 or a == c2:
ball += 1
if b == b2:
strike += 1
if b == a2 or b == c2:
ball += 1
if c == c2:
strike += 1
if c == a2 or c == b2:
ball += 1
if not (strike == games[j][1] and ball == games[j][2]):
is_answer = False
break
if is_answer:
count += 1
print(count)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 1145๋ฒ / ์ ์ด๋ ๋๋ถ๋ถ์ ๋ฐฐ์ [Go][Python3] (0) | 2021.01.25 |
---|---|
BOJ / 1969๋ฒ / DNA [Go][Python3] (0) | 2021.01.24 |
BOJ / 17626๋ฒ / Four Squares [Go][Python3] (0) | 2021.01.21 |
BOJ / 19947๋ฒ / ํฌ์์ ๊ท์ฌ ๋ฐฐ์ฃผํ [Go][Python3] (0) | 2021.01.20 |
BOJ / 9655๋ฒ / ๋ ๊ฒ์ [Go][Python3] (0) | 2021.01.19 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ์๋ฐ
- BFS
- java
- ์คํ
- baekjoon
- ํด์๋งต
- ํ๋ก์ด๋์์ฌ
- BOJ
- MongoDB
- python3
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- AWS
- ๋งฅ๋ถํ๋ก
- ํ
- ์๊ฐ๊ต์ฒด
- ๋งฅ๋ถ
- ์๊ณ ๋ฆฌ์ฆ
- ๋ถํ ์ ๋ณต
- ๋ชฝ๊ณ ๋๋น
- ๋ธ๋ฃจํธํฌ์ค
- Macbook pro 2012 mid 13
- dfs
- go
- ์ด๋ถํ์
- Golang
- dp
- ballet
- ๋ฐ๋
- ๋ฐฑ์ค
- Algorithm
- Total
- Today
- Yesterday