ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

1475๋ฒˆ: ๋ฐฉ ๋ฒˆํ˜ธ

์ฒซ์งธ ์ค„์— ๋‹ค์†œ์ด์˜ ๋ฐฉ ๋ฒˆํ˜ธ N์ด ์ฃผ์–ด์ง„๋‹ค. N์€ 1,000,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜ ๋˜๋Š” 0์ด๋‹ค.

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ 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
๋Œ“๊ธ€