본문 바로가기

Algorithm/Algospot

[algospot]MISPELL

문제

https://algospot.com/judge/problem/read/MISPELL

문자열에서 n번째를 지우는 프로그램을 짜라!. 

 

입력

지울문자위치(M)에 한칸띄우고 입력문자열 .문자열은 80글자 이하

 

출력

라인숫자 + 공백 + 결과문자열

 

풀이

문자열을 char배열로 바꾼뒤에 지울문자위치빼고 문자열 모아서 출력~

출력에 라인숫자를 찍어줘야하는 함정에 빠지면 안된다.많이들 낚이는것 같다;;

 

 

package com.tutorial;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class MISPELL {
    public static void main(String[] args)throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System. in));
        int cnt = Integer.parseInt(br.readLine());
        int total = cnt;
        while (cnt -- > 0) {
            String[] s = br.readLine().split(" ");
            char[] c = s[1].toCharArray();
            int b = Integer.parseInt(s[0]) - 1;
            String result = "";
            for (int i = 0; i < c.length; i ++) {
                if (b != i) 
                    result += c[i];
                
            }
            System.out.println((total - cnt) + " " + result);
        }
    }
}

 

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

[algospot]HOTSUMMER  (0) 2014.12.11
[algospot]CONVERT  (0) 2014.12.11
[algospot]ENCRYPT  (0) 2014.12.11
[algospot]LECTURE  (0) 2014.12.11
[algospot]ENDIANS  (0) 2014.12.11