본문 바로가기
Programming/>> Algorithm

[Lucky Algorithm] Birthday Cake Candles

by 니키ᕕ( ᐛ )ᕗ 2017. 10. 3.

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 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 Format

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


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        for(int i=0; i<n; i++) {
            StringBuilder builder = new StringBuilder();

            for(int j=0; j<(n-1-i); j++) builder.append(" ");
            for(int j=(n-1-i); j<n; j++) builder.append("#");

            System.out.println(builder.toString());
        }
    }
}


'Programming > >> Algorithm' 카테고리의 다른 글

[Lucky Algorithm] Super Reduced String  (0) 2017.10.04
[Lucky Algorithm] Time Conversion  (0) 2017.10.04
[Lucky Algorithm] Staircase  (0) 2017.10.03
[Lucky Algorithm] Plus Minus  (0) 2017.10.03
[Lucky Algorithm] Diagonal Difference  (0) 2017.10.03

댓글