问题是
只能用这些积木
积木限制64块
c++代码也可以的(不要太长就好)
#include <stdio.h>
int main()
{
// 读入字符串 (scratch中可忽略)
char string[17] = {'\0'};
fgets(string, 17, stdin);
// 计算字符串长度 (scratch中可忽略)
int len = 0;
for (int i = 0; i < 17; i++)
{
if (string[i] == '\n')
{
len = i;
string[i] = '\0';
break;
}
}
// printf("%s\n", string);
// printf("len: %d, string: %s\n", len, string);
// rep代表重复长度
int rep = 1;
for (; rep < len; rep++)
{
// 句子长度应是重复长度的倍数
if (len % rep != 0)
continue;
int isrep = 1;
// 以后的每一段是从m到m+rep
for (int m = rep; m < len; m += rep)
{
// 判断这一段是否与第一段相同
for (int i = 0; i < rep; i++)
{
if (string[m + i] != string[i])
{
isrep = 0;
}
}
}
if (isrep)
{
break;
}
}
char str2[17] = {'\0'};
for (int i = 0; i < rep; i++)
{
str2[i] = string[i];
}
printf("%d %s", rep, str2);
return 0;
}