Recommanded Free YOUTUBE Lecture: <% selectedImage[1] %>

Contents

생일 케이크 준비하기

매년 조카의 생일케이크를 준비해야 하는 임무가 주어졌다. 당신은 케이크와 함께 조카의 나이 만큼의 초도 준비해야 한다. 케익을 받은 조카가 촛불을 끄기위해서 바람을 불면, 그 중 가장 길이가 긴 촛불이 꺼지게 된다. 조카가 바람을 불었을 때 몇 개의 촛불이 꺼질지를 계산해야 한다.

예를 들어 4살 조카의 생일 케이크라면 4개의 초도 함께 준비해야 할 것이다. 초의 길이가 3, 2, 1, 3 이라면, 이 중 가장 긴 초의 길이는 3일테고 두개의 촛불이 꺼질 것이다.

나이 와 초의 크기가 주어지면 몇 개의 촛불이 꺼질지를 계산하는 프로그램을 만들자.

입력 형식

  1. 첫번째 줄은 케이크에 꽂을 초의 갯수 n 이다.
  2. 두번째 줄은 각 초의 길이 height다.

제약 조건

출력 포맷

꺼진 초의 갯수를 표준출력 한다.

예제

입력이 아래와 같을 때
4
3 2 1 3
출력은 아래와 같다.
2

코드

golang

package main

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

type BirthdayCake struct {
    age    int
    candle []int
}

func CakeSetting(age int, candle []int) *BirthdayCake {
    b := &BirthdayCake{age, candle}
    return b
}

func (b *BirthdayCake) blow() int {
    max := 0
    count := 0
    for _, v := range b.candle {
        switch {
        case v == max:
            count++
        case v > max:
            max = v
            count = 1
        }
    }
    return count
}

func main() {
    var (
        text string
        arg  []int
    )
    reader := bufio.NewReader(os.Stdin)
    text, _ = reader.ReadString('\n')
    text, _ = reader.ReadString('\n')
    text = strings.Trim(text, "\n")

    inputStr := strings.Split(text, " ")

    for _, v := range inputStr {
        vi, _ := strconv.Atoi(v)
        arg = append(arg, vi)
    }
    myCake := CakeSetting(4, arg)
    fmt.Println(myCake.blow())
}

python