Lined Notebook

[4406] [Java] 모음이 보이지 않는 사람

by HeshAlgo

<모음이 보이지 않는 사람>

문제 설명

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWNcD_66pUEDFAV8&categoryId=AWNcD_66pUEDFAV8&categoryType=CODE

 

내 생각

완전 탐색을 활용해 문제를 풀이했습니다. 모음이 없을 경우 조건문을 통해 문자를 더해주는 식으로 구현을 해보았습니다. 

 

푼 시간

21분 45초

 

작성 코드

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
// 모음이 보이지 않는 사람
import java.io.FileInputStream;
import java.util.*;
 
public class Main {
 
    public static void main(String args[]) throws Exception {
        String path = "input.txt";
        System.setIn(new FileInputStream(path));
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        
        for(int test_case = 1; test_case <= t; test_case++) {
            String word = sc.next();
            StringBuffer sb = new StringBuffer(word);
            String answer = "";
            
            for (int i = 0; i < sb.length(); i++) {
                char ch = sb.charAt(i);
                
                if ('a' != ch && 'e' != ch && 'i' != ch && 'o' != ch && 'u' != ch) {
                    answer += ch;
                }
                
            }
            
            System.out.println("#" + test_case + " " + answer);
            
        }
        
    }
    
}
 
 

 

실행 결과

블로그의 정보

꾸준히 공부하는 개발 노트

HeshAlgo

활동하기