-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathquestion2.c
75 lines (55 loc) · 805 Bytes
/
question2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
int hash[256];
int cal(char *str){
int k;
for(k=0;k<256;k++){
hash[k] = 0;
}
int length = strlen(str);
int allEqual = true;
int mid = length/2;
int max = 0;
int i = 0;
int j = mid;
int count = 0;
while(i<mid && j<length){
if(str[i] == str[j]){
i++;
j++;
count++;
if(max < count){
max = count;
}
}else{
if(i == 0){
j++;
}
i = 0;
count = 0;
max = 0;
}
}
int z;
for(z=0;z<length;z++){
hash[str[z]]++;
}
if(hash[str[0]] == length){
return length-1;
}
return max;
}
int main(){
int cases;
scanf("%d", &cases);
int i;
char str[100000];
for(i=0;i<cases;i++){
scanf("%s",str);
int ans = cal(str);
printf("%d\n", ans);
}
return 0;
}