본문 바로가기

programming/algorithm 공부

[Algorithm] Birthday Cake Candles


안녕하세요. Bot - binoo 입니다.

> Hi, I am Bot-binoo.

이번에 풀어볼 문제는 Birthday Cake Candles 입니다.

The problem to solve this time is Birthday Cake Candles.

> Header : copyrighted by Bot-binoo.


> Post.


> Quest.

Colleen is turning  years old! Therefore, she has  candles of various heights on her cake, and candle  has height . Because the taller candles tower over the shorter ones, Colleen can only blow out the tallest candles.

Given the  for each individual candle, find and print the number of candles she can successfully blow out.



> Input.

Input Format

The first line contains a single integer, , denoting the number of candles on the cake. 
The second line contains  space-separated integers, where each integer  describes the height of candle .

Constraints



> Output.

Output Format

Print the number of candles Colleen blows out on a new line.

Sample Input 0

4
3 2 1 3

Sample Output 0

2

Explanation 0

We have one candle of height , one candle of height , and two candles of height . Colleen only blows out the tallest candles, meaning the candles where . Because there are  such candles, we print  on a new line.



> solve

*차후 큐와 스택, 데크와 관련된 설명을 추가하겠습니다.


문제는 단순합니다. 

큐와 스택에 각각의 문자열을 저장합니다.

큐와 스택이 출력시 같은 문자를 계속 뱉고 끝나면 palindrome .

하나라도 다르면 is not a palindrome. 추가로 출력하면 됩니다.


palindrome : 회문(回文: madam이나 nurses run처럼 앞에서부터 읽으나 뒤에서부터 읽으나 동일한 단어나 구)


문제는 케이크 초 중에서 가장 길이가 긴 것이 모두 몇개인지 세는 문제입니다.

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int birthdayCakeCandles(int n, int ar_size, int* ar) {
    int max = 0;
    int cnt = 0;
    for( int i = 0; i < ar_size; i++ ){
        max =  ( ((*(ar+i) > *(ar+ar_size-1-i)) ? *(ar+i) : *(ar+ar_size-1-i)) > max ? ((*(ar+i) > *(ar+ar_size-1-i)) ? *(ar+i) : *(ar+ar_size-1-i)) : (max) );
    }
    for( int i = 0; i < ar_size; i++ ){
        cnt = ((max == *(ar+i)) ? (cnt + 1) : (cnt) );
    }
    return cnt;
}
/* 기본제공 main 코드 */
int main() {
    int n; 
    scanf("%i", &n);
    int *ar = malloc(sizeof(int) * n);
    for(int ar_i = 0; ar_i < n; ar_i++){
       scanf("%i",&ar[ar_i]);
    }
    int result = birthdayCakeCandles(n, n, ar);
    printf("%d\n", result);
    return 0;
}


상기의 코드는 C 로 작성되었습니다.

> Main post : copyrighted by Bot-binoo.


> Summary.

이번에는 Birthday Cake Candles 에 대한 풀이였습니다. 

부족한 내용이나 참고할 만한 자료가 있으시다면 언제든지 댓글로 남겨주세요.

This time, it was a solution to Birthday Cake Candles.

If you have any reference material, please feel free to leave a comment.

> Summary : copyrighted by Bot-binoo.


Finishing the article.

읽어주신, 또한 찾아주신 분들께 감사 인사드립니다.

Thank you.

> Footer : copyrighted by Bot-binoo.



반응형