java
패턴에서 반복되는 부분을 마디라고 부른다. 문자열을 입력 받아 마디의 길이를 출력하는 문제
반복문과 조건문을 활용해 문제를 풀었다.
어렵지 않게 해결한 문제
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 input = sc.next();
int length = input.length();
int patternLength = length;
for (int pl = 1; pl <= length; pl++) {
String pattern = input.substring(0, pl);
boolean isPatternRepeating = true;
for (int i = 0; i + pl <= length; i += pl) {
if (!pattern.equals(input.substring(i, i + pl))) {
isPatternRepeating = false;
break;
}
}
if (isPatternRepeating) {
patternLength = pl;
break;
}
}
System.out.printf("#%d %d\n", test_case, patternLength);
}
}
}
Java테스트 시 의존성 주입(Dependency Injection)과 Mockito Spring 애플리케이션을 개발하다 보면, 테스트 코드에서 실제 빈(Bean)을 사용하지…
들어가며 스프링 기반 프로젝트에서 좋은 설계 구조와 테스트 전략은 소프트웨어 품질과 유지보수성에 직결됩니다. 최근 학습한…
Readable Code: 읽기 좋은 코드를 작성하는 사고법Practical Testing: 실용적인 테스트 가이드 강의와 함께한 인프런 워밍업 클럽…
Readable Code: 읽기 좋은 코드를 작성하는 사고법Practical Testing: 실용적인 테스트 가이드 강의와 함께한 인프런 워밍업 클럽…
들어가며 코드를 작성할 때 종종 "이 로직을 어떻게 단순하고 읽기 쉽게 표현할 수 있을까?" 고민하게…