Home 백준 단어 공부 1157
Post
Cancel

백준 단어 공부 1157

백준 1157 알고리즘

https://www.acmicpc.net/problem/1157

"1157"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var temp map[string]int = make(map[string]int)

func main() {
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var text string
	r := bufio.NewReader(os.Stdin)
	fmt.Fscanln(r, &text)

	splits := strings.Split(strings.ToUpper(text), "")
	for _, v := range splits {
		cnt := temp[v]
		temp[v] = cnt + 1
	}

	var result string
	var maxWord int = -1
	for key, value := range temp {
		if value > maxWord {
			result = key
			maxWord = value
		} else if value == maxWord {
			result = "?"
		}
	}

	fmt.Fprintln(w, result)
}

This post is licensed under CC BY 4.0 by the author.