AcWing 777. 字符串乘方--java
原题链接
困难
作者:
Myo
,
2023-02-07 11:50:14
,
所有人可见
,
阅读 149
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = "";
while (!(str = sc.nextLine()).equals(".")) {
int len = str.length();
for (int i = len; i > 0; i--) {
if (len % i != 0) {
continue;
}
// 此时i一定是len的因数
// str可以分为等长的i段,使用split方法去除,剩余字符数组长度为0则符合要求
String[] res = str.split(str.substring(0, len / i));
if (res.length == 0) {
System.out.println(i);
break;
}
}
}
}
}