문제

Now that Snapchat and Slingshot are soooo 2018, the teenagers of the world have all switched to the new hot app called BAPC (Bidirectional and Private Communication). This app has some stricter social rules than previous iterations. For example, if someone says goodbye using Later!, the other person is expected to reply with Alligator!. You can not keep track of all these social conventions and decide to automate any necessary responses, starting with the most important one: the greetings. When your conversational partner opens with he...ey, you have to respond with hee...eey as well, but using twice as many e’s!

Given a string of the form he...ey of length at most 1000, print the greeting you will respond with, containing twice as many e’s.

 

입력

  • The input consists of one line containing a single string s as specified, of length at least 3 and at most 1000.

 

출력

Output the required response.


코드

import java.util.Scanner;

public class 백준_17548 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String st = sc.next();

        int eCount = 0;
        
        for(int i = 0; i < st.length(); i++){
            char c = st.charAt(i);
            if(c == 'e'){
                eCount += 1;
            }
        }
        System.out.print("h");
        for(int i = 0; i < eCount*2; i++){
            System.out.print("e");
        }
        System.out.print("y");
    }
}

 

풀이

문제를 해석해보면 입력 String의 e를 2배로 출력하면 된다. 최소 입력은 'hey'이다.

입력받은 String에서 e의 개수를 세서 eCount 변수에 저장했다. 

출력은 h, e, y를 따로 출력해 e를 중간에 여러 개 출력할 수 있도록 했다.

728x90

'Algorithm > 백준' 카테고리의 다른 글

[백준][Java] 1912. 연속합  (0) 2022.04.28
[백준][Python] 19604. Art  (0) 2022.04.25
[백준][Java] 1934. 최소공배수  (0) 2022.04.17
[백준][Java] 2579. 계단 오르기  (0) 2022.04.13
[백준][Java] 1904. 01타일  (0) 2022.04.11

+ Recent posts