1일 1알고/알고리즘 재활 프로젝트

SWEA 2007. 패턴 마디의 길이 (Java)

yeong. 2021. 12. 3. 13:21

문자열 문제는 보면 머리가 굳어버리는 것 같다.

다행이(?) 문제 조건이 널널해서 풀긴 했지만 시간이 오래 걸렸다.

 

package week1;

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

public class Solution_패턴마디의길이 {
	
	static int N, TC;
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		TC=Integer.parseInt(br.readLine());
		
		for(int tc=1;tc<=TC;tc++) { 
			String input= br.readLine();
			int now;
			
			for(now=1;now<10;now++) {
								
				if(input.substring(0, now).equals(input.substring(now, now+now))) {
					break;
				}
				
			}
			
			System.out.println("#"+tc+" "+now);
			
		}// end tc
	}

}