-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsdjj.cpp
More file actions
60 lines (55 loc) · 771 Bytes
/
sdjj.cpp
File metadata and controls
60 lines (55 loc) · 771 Bytes
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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
string a;
while(t--)
{
cin>>a;
int l=a.length();
int arr[l];
int j=0,m=0,n=0;
arr[0]= 0;
int i=1;
while(i<l)
{
if(a[i]==a[j])
{
j++;
arr[i]=j;
i++;
}
else
{
if(j!=0)
{
j=arr[j-1];
}
else{
arr[i]=0;
i++;
}
}
}
for(int i=l-1;i>=0;i--)
{
if(a[i]=='I'){
m=i;
break;
}
}
for(int i=l-1;i>=0;i--)
{
if(a[i]=='O'){
n=i;
break;
}
}
w if(m!=0)
cout<<arr[m];
else
cout<<0;
}
}