ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/1302
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n int
fmt.Fscanln(reader, &n)
var sold = map[string]int{}
for i := 0; i < n; i++ {
var title string
fmt.Fscanln(reader, &title)
sold[title]++
}
counts := []soldCount{}
for k, v := range sold {
counts = append(counts, soldCount{k, v})
}
sort.Slice(counts, func(i, j int) bool {
if counts[i].count > counts[j].count {
return true
} else if counts[i].count == counts[j].count {
return counts[i].title < counts[j].title
}
return false
})
fmt.Fprintln(writer, counts[0].title)
}
type soldCount struct {
title string
count int
}
๐จ Python3
# https://www.acmicpc.net/problem/1302
import sys
if __name__ == "__main__":
n = int(sys.stdin.readline())
sold = {}
for i in range(n):
title = sys.stdin.readline().rstrip()
if sold.get(title):
sold[title] += 1
else:
sold[title] = 1
counts = [(key, sold[key]) for _, key in enumerate(sold)]
counts = sorted(counts, key=lambda x: (-x[1], x[0]))
print(counts[0][0])
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 10799๋ฒ / ์ ๋ง๋๊ธฐ [Go][Python3] (0) | 2021.02.06 |
---|---|
BOJ / 17219๋ฒ / ๋น๋ฐ๋ฒํธ ์ฐพ๊ธฐ [Go][Python3] (0) | 2021.02.05 |
BOJ / 3986๋ฒ / ์ข์ ๋จ์ด [Go][Python3] (0) | 2021.02.03 |
BOJ / 1620๋ฒ / ๋๋์ผ ํฌ์ผ๋ชฌ ๋ง์คํฐ ์ด๋ค์ [Go][Python3] (0) | 2021.02.02 |
BOJ / 10845๋ฒ / ํ [Go][Python3] (0) | 2021.02.01 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ๋ธ๋ฃจํธํฌ์ค
- ์๊ณ ๋ฆฌ์ฆ
- ๋ชฝ๊ณ ๋๋น
- dp
- python3
- Algorithm
- baekjoon
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- java
- dfs
- ์คํ
- ๋ฐฑ์ค
- ์๊ฐ๊ต์ฒด
- ํ๋ก์ด๋์์ฌ
- ballet
- AWS
- MongoDB
- ๋ฐ๋
- ๋งฅ๋ถํ๋ก
- Golang
- ํด์๋งต
- BOJ
- ์๋ฐ
- ํ
- ๋งฅ๋ถ
- ๋ถํ ์ ๋ณต
- BFS
- go
- ์ด๋ถํ์
- Macbook pro 2012 mid 13
- Total
- Today
- Yesterday