본문 바로가기

Algorithm/Algospot

[algospot]ENCRYPT

문제

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

메세지암호화

입력받은 문자열에대해서 짝수자리 번호들은 왼쪽으로 붙이고 홀수자리 숫자들은 오른쪽으로 붙인다.

마치 손가락 깍지 낀 상태에서 깍지를 푼다음의 상태라고 할까나;;

 

입력

공백이포함되지않는 100자 이하 문자열

 

출력

암호화된 문자열

 

풀이

입력받은 문자열에 대해서 홀짝검사를 해서 문자열을 각각 모은다음에 출력.

 

 

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

 

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

[algospot]CONVERT  (0) 2014.12.11
[algospot]MISPELL  (0) 2014.12.11
[algospot]LECTURE  (0) 2014.12.11
[algospot]ENDIANS  (0) 2014.12.11
[algospot]MERCY  (0) 2014.12.11