ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [BaekJoon/Java] 4659. 비밀번호 발음하기 - A049
    2022_PPS/3주차 2023. 1. 19. 10:37

    -  문제

     

    -  알고리즘

    먼저 while문을 이용하여 문자열을 받아준다.

    받은 문자열이 end라면 바로 종료하도록 하고, 문자열을 출력하기 위해 저장해 준다.

    문자열을 반복문에 넣어 모음이 포함되어 있는지 확인한다.

    모음과 자음이 연속되는지를 확인하기 위해 변수의 크기를 키워준다.

    모음이 필수로 들어가야 하기 때문에 vowelCheak변수를 이욯하였고, vowels, collocation 변수를 통해 연속 3개가 나오는지 확인하였다.

    또 연속으로 같은 글자가 오는지도 함께 확인해 줬다.

    그 반복문을 마치고 나면 vowelCheak가 true인지를 확인하여 cheak를 바꿔준다.

    cheakList에 cheak의 값을 넣고, whlie문이 끝나면 형식에 맞게 출력해 준다.

     

    -  코드

    import java.util.Scanner;
    import java.util.ArrayList;
    
    class Main {
      public static void main(String[] args) {
    	  Scanner s = new Scanner(System.in);
    	  ArrayList<Boolean> cheakList = new ArrayList<Boolean>();
    	  ArrayList<String> list = new ArrayList<String>();
    
    	  while(true){
    		  String str = s.next();
    		  if(str.equals("end")) break;
    		  list.add(str);
    		  boolean cheak = true;
    		  boolean vowelCheak = false;
    		  int vowels = 0;
    		  int collocation = 0;
    		  
    		  for(int i = 0; i<str.length(); i++){
    			  if(str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o' || str.charAt(i) == 'u'){
    				  vowels++;
    				  collocation = 0;
    				  vowelCheak = true;
    			  }else{
    				  collocation++;
    				  vowels = 0;
    			  }
    
    			  if(vowels == 3 || collocation == 3){
    				  cheak = false;
    				  break;
    			  }
    
    			  if((i != str.length()-1) && (str.charAt(i) == str.charAt(i+1))){
    				  if(str.charAt(i) != 'e' && str.charAt(i) != 'o'){
    					  cheak = false;
    					  break;
    				  }
    			  }
    		  }
    
    		  if(!vowelCheak) cheak = false;
    		  cheakList.add(cheak);
    	  }
    	  
    	  for(int i = 0; i<list.size(); i++){
    		  if(cheakList.get(i)) System.out.println("<" + list.get(i) + "> is acceptable.");
    		  else System.out.println("<" + list.get(i) + "> is not acceptable.");
    	  }
      }
    }
Designed by Tistory.