Codeforces Round #751 (Div. 2) - A. Two Subsequences

HoJeong Im·2021년 10월 25일
0

Codeforces

목록 보기
1/13

문제

코드

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

// https://codeforces.com/contest/1602/problem/A
// 2021-10-25 Java - 문제 풀이

public class Two_Subsequences {
	
	static BufferedReader br;
	static int N, target;
	static char[] arr;
	
	static int toInt(String msg) {
		return Integer.parseInt(msg);
	}
	static char[] toCharArray(String msg) {
		return msg.toCharArray();
	}
	public static void main(String[] args) throws IOException{
		br = new BufferedReader(new InputStreamReader(System.in));
		N = toInt(br.readLine());
		for(int test = 0 ; test < N ; test++) {
			arr = toCharArray(br.readLine());
			
			int minValue = Integer.MAX_VALUE;
			int minIndex = Integer.MAX_VALUE;
			for(int i = 0 ; i < arr.length ; i++) {
				if(minValue > arr[i]) {
					minValue = arr[i];
					minIndex = i;
				}
			}
//			System.out.println(minValue+" "+minIndex);
			char[] left = Arrays.copyOfRange(arr, 0, minIndex);
			char[] right = Arrays.copyOfRange(arr, minIndex+1, arr.length);
			
			StringBuffer stb = new StringBuffer();
			
			for(int i = 0; i < left.length ; i++) {
				stb.append(left[i]);
			}
			for(int i = 0; i < right.length ; i++) {
				stb.append(right[i]);
			}
			
			System.out.println(arr[minIndex] +" "+stb);
			
		}
		
		
	}
	
}


회고

  • 기본적인 문자를 다루는 문제라고 생각합니다.

  • java를 정해서 볼 거라면, 기본 문법 먼저 손에 익혀서 사용해야 합니다!

  • Arrays.copyOfRange

  • 함수로 사용하는 습관을 들이자

  • 그 자리만 출력하지 않는 방식도 괜찮은 방법인듯?

추가

profile
꾸준함이 제일 빠른 길이었다

0개의 댓글