Skip to content

Instantly share code, notes, and snippets.

@jojoldu
Created May 10, 2016 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jojoldu/7d2a7451aa2345c71a0e3193fa2a51d5 to your computer and use it in GitHub Desktop.
Save jojoldu/7d2a7451aa2345c71a0e3193fa2a51d5 to your computer and use it in GitHub Desktop.
boj-1305
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
private static int line;
private static String base;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
line = Integer.parseInt(br.readLine());
base = br.readLine();
String prefix;
String suffix;
StringBuilder firstEqual = null;
for (int i = 0; i < line; i++) {
prefix = base.substring(0, i + 1);
suffix = base.substring(line - i - 1, line);
char appender = prefix.charAt(0); // aaaaaabaaaaa 같은 경우를 위한 체크용
if (prefix.equals(suffix)) {
if (firstEqual == null) {
firstEqual = new StringBuilder(prefix);
} else {
firstEqual.append(appender);
if(prefix.equals(firstEqual.toString())){
if (i == line - 1) {
System.out.println(1);
}
}else{
System.out.println(prefix.length() - (firstEqual.length()-1)); //마지막 비교로 append된 부분 삭제
break;
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment