好久没刷过题,昨晚在某人监督下开始刷题啦
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=6&problem=396&mosmsg=Submission+received+with+ID+19558285
这是链接 好久木有用过c/cpp的缘故,好多细节都忘了。导致踩了好几个坑。最坑的还是要两个换行符了,一开始没注意,wa了n次还摸不着头脑。
#include <iostream>
#include "stdio.h"
#include "string.h"
int main() {
int N = 0;
char s[82];
scanf("%d",&N);
while (N--){
scanf("%s",s);
int n = strlen(s);
for (int i = 0; i < n; ++i) {
if (n% (i + 1) == 0){
bool flag = true;
for (int j = (i + 1); j < n; ++j) {
if (s[j % (i + 1)] != s[j]){
flag = false;
break;
}
}
if (flag == true){
printf("%d\n",i + 1);
if (N != 0){ printf("\n");}
break;
}
}
}
}
return 0;
}