문제

이 문제의 포인트는 모음('a','e','i','o','u')이 나왔을때 그다음이 'p'과 그 다음다음이 똑같은 모음이여야한다는 것이다. 뒤에 똑같은 모음이 온다는것을 못보고 코드를 구현하고 실패하자 문제를 다시 읽고 수정하였다. (안좋은 습관 또!!)

 

 

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
import java.util.*;
 
public class Main{
    public static boolean flag=false;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str=sc.nextLine();
        String result="";
        for(int i=0;i<str.length();i++) {
            if((str.charAt(i)=='a'&&str.charAt(i+1)=='p')||(str.charAt(i)=='e'&&str.charAt(i+1)=='p')||(str.charAt(i)=='i'&&str.charAt(i+1)=='p')||(str.charAt(i)=='o'&&str.charAt(i+1)=='p')||(str.charAt(i)=='u'&&str.charAt(i+1)=='p')) {
                result+=str.charAt(i);
                i=i+2;
                flag=true;
            }
            if(flag==false)
            {
                result+=str.charAt(i);
            }
            else if(flag==true)
            {
                flag=false;
            }
        }
        System.out.println(result);
    }
}
 
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter

https://www.acmicpc.net/problem/2954

 

2954번: 창영이의 일기장

문제 창영이는 매일 밤 하루동안 일어난 일을 일기장에 남긴다. 일기장을 쓰면서 영어 공부도 같이 하기 위해서 영어로 일기를 쓴다. 또, 남들이 자신의 일기장을 보는 것을 막기 위해서 모음('a','e','i','o','u')의 다음에 'p'를 하나 쓰고,  그 모음을 하나 더 쓴다. 예를 들어, "kemija" 는 "kepemipijapa"가 되고, "paprika"는 "papapripikapa"가 된다. 창영이가 일기장에 작성한 문장이 하나 주어졌을 때

www.acmicpc.net

 

'알고리즘 > 문제' 카테고리의 다른 글

수학숙제  (0) 2019.07.13
퍼거슨과 사과  (0) 2019.07.08
찍기  (0) 2019.07.08
2009년  (0) 2019.07.08
캔디구매  (0) 2019.07.08

+ Recent posts