AcWing 777. 字符串乘方 - Java
原题链接
困难
作者:
KYCygni
,
2021-03-19 07:46:06
,
所有人可见
,
阅读 298
Java 代码
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
String s = cin.next();
while (s.compareTo(".") != 0)
{
int len = s.length();
for (int i = 1; i <= len; i ++)
{
if (len % i == 0)
{
int c = len / i;
String sub = s.substring(0, i);
String s2 = "";
for (int j = 0; j < c; j ++)
{
s2 += sub;
}
if (s.compareTo(s2) == 0)
{
System.out.println (c);
break;
}
}
}
s = cin.next();
}
}
}