ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/1475
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)
if n == 0 {
fmt.Fprintln(writer, 1)
return
}
numberCount := map[int]int{}
for n > 0 {
numberCount[n%10]++
n /= 10
}
sixCount, nineCount := numberCount[6], numberCount[9]
if (sixCount+nineCount)%2 == 0 {
numberCount[6] = (sixCount + nineCount) / 2
numberCount[9] = numberCount[6]
} else {
numberCount[6] = (sixCount + nineCount) / 2
numberCount[9] = numberCount[6] + 1
}
var setCount int
for _, v := range numberCount {
if setCount < v {
setCount = v
}
}
fmt.Fprintln(writer, setCount)
}
๐จ Python3
# https://www.acmicpc.net/problem/1475
import sys
if __name__ == "__main__":
n = int(sys.stdin.readline())
number_count = {}
if n == 0:
print(1)
sys.exit()
number_count = {}
while n > 0:
if number_count.get(n%10):
number_count[n%10] += 1
else:
number_count[n%10] = 1
n //= 10
six_count = number_count.get(6) if number_count.get(6) else 0
nine_count = number_count.get(9) if number_count.get(9) else 0
if (six_count+nine_count)%2 == 0:
number_count[6] = (six_count+nine_count)//2
number_count[9] = number_count[6]
else:
number_count[6] = (six_count+nine_count)//2
number_count[9] = number_count[6] + 1
set_count = max(number_count.values())
print(set_count)
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 1991๋ฒ / ํธ๋ฆฌ ์ํ [Go][Python3] (0) | 2021.03.25 |
---|---|
BOJ / 11057๋ฒ / ์ค๋ฅด๋ง ์ [Go][Python3] (0) | 2021.03.24 |
BOJ / 6603๋ฒ / ๋ก๋ [Go][Python3] (0) | 2021.03.22 |
BOJ / 1182๋ฒ / ๋ถ๋ถ์์ด์ ํฉ [Go][Python3] (0) | 2021.03.21 |
BOJ / 9465๋ฒ / ์คํฐ์ปค [Go][Python3] (0) | 2021.03.20 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- Algorithm
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- AWS
- ์๋ฐ
- ํด์๋งต
- ๋ฐ๋
- ballet
- python3
- ์ด๋ถํ์
- ๋ฐฑ์ค
- Golang
- ๋งฅ๋ถํ๋ก
- java
- BOJ
- ํ๋ก์ด๋์์ฌ
- ์คํ
- BFS
- ๋ธ๋ฃจํธํฌ์ค
- ํ
- ๋ถํ ์ ๋ณต
- dp
- ์๊ฐ๊ต์ฒด
- Macbook pro 2012 mid 13
- ์๊ณ ๋ฆฌ์ฆ
- ๋งฅ๋ถ
- baekjoon
- ๋ชฝ๊ณ ๋๋น
- MongoDB
- dfs
- go
- Total
- Today
- Yesterday