SWEA

[SWEA] 패턴 마디의 길이

itsnot4me 2024. 9. 21. 19:48

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5P1kNKAl8DFAUq&categoryId=AV5P1kNKAl8DFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=1

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

import java.util.Scanner;
import java.io.FileInputStream;

class Solution
{
	public static void main(String args[]) throws Exception
	{
	
		Scanner sc = new Scanner(System.in);
		int T;
		T=sc.nextInt();
		for(int test_case = 1; test_case <= T; test_case++)
		{
            String word = sc.next();
			for(int i=1; i<word.length(); i++){
             	String repeat1 = word.substring(0,i);
                String repeat2 = word.substring(i,i+i);
                if(repeat1.equals(repeat2)){
                 	System.out.println("#" + test_case + " " + repeat1.length());   
                    break;
                }
                    
            }

		}
	}
}

 

문자열 받고, 같은 구간 있는지 확인 후, #testcase '길이' 출력

구간 0부터 0은 계속 같으므로 시작점 1로 설정 (i)

'SWEA' 카테고리의 다른 글

[SWEA] 파리 퇴치  (0) 2024.09.25
[SWEA] 파스칼의 삼각형  (1) 2024.09.24
[SWEA] 간단한 369게임  (0) 2024.09.20
[SWEA] +=  (1) 2024.09.20
[SWEA] 거꾸로 출력해 보아요  (0) 2024.09.20