Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 22af7d0

Browse files
Back after a break from CN
1 parent 17daf58 commit 22af7d0

File tree

6 files changed

+138
-0
lines changed

6 files changed

+138
-0
lines changed

‎String/0000000000000183s.zip‎

1.76 KB
Binary file not shown.

‎String/KMP‎

22.6 KB
Binary file not shown.

‎String/KMP.cpp‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
3+
Name: Mehul Chaturvedi
4+
IIT-Guwahati
5+
6+
*/
7+
8+
/*
9+
PROBLEM STATEMENT
10+
11+
*/
12+
13+
#include <bits/stdc++.h>
14+
using namespace std;
15+
16+
typedef long long ll;
17+
typedef unordered_map<int, int> umapii;
18+
typedef unordered_map<int, bool> umapib;
19+
typedef unordered_map<string, int> umapsi;
20+
typedef unordered_map<string, string> umapss;
21+
typedef map<string, int> mapsi;
22+
typedef map<pair<int, int>, int> mappiii;
23+
typedef map<int, int> mapii;
24+
typedef pair<int, int> pii;
25+
typedef pair<long long, long long> pll;
26+
typedef unordered_set<int> useti;
27+
28+
#define uset unordered_set
29+
#define it iterator
30+
#define mp make_pair
31+
#define pb push_back
32+
#define all(x) (x).begin(), (x).end()
33+
#define f first
34+
#define s second
35+
#define MOD 1000000007
36+
37+
// S and T - input strings
38+
// You need to check if string T is present in S or not
39+
40+
int findString(char S[], char T[]) {
41+
int length = strlen(T);
42+
int n = strlen(S);
43+
44+
45+
vector<int> pitable(length, 0);
46+
int i = 0;
47+
int j = i+1;
48+
49+
while(j<length && i<length){
50+
if (T[i]==T[j])
51+
{
52+
pitable[j] = i+1;
53+
i++;
54+
j++;
55+
}else
56+
{
57+
if (i!=0)
58+
{
59+
i = pitable[i-1];
60+
61+
}
62+
j++;
63+
}
64+
}
65+
66+
// for (int k = 0; k < length; ++k)
67+
// {
68+
// cout << pitable[k] << ' ';
69+
// }
70+
// cout << '\n';
71+
// return 0;
72+
73+
int p = 0;
74+
int q = 0;
75+
while(q<length && p<n){
76+
if (S[p] == T[q])
77+
{
78+
p++;
79+
q++;
80+
}else
81+
{
82+
//cout << "here" << '\n';
83+
if (q==0)
84+
{
85+
p++;
86+
continue;
87+
}
88+
q = pitable[q-1];
89+
}
90+
}
91+
92+
if (q==length)
93+
{
94+
return p-length;
95+
}
96+
97+
98+
return -1;
99+
100+
}
101+
102+
103+
int main( int argc , char ** argv )
104+
{
105+
ios_base::sync_with_stdio(false) ;
106+
cin.tie(NULL) ;
107+
108+
109+
char S[1000], T[1000];
110+
cin.getline(S, 1000);
111+
cin.getline(T, 1000);
112+
cout<<findString(S, T)<<endl;
113+
114+
115+
116+
return 0 ;
117+
118+
119+
120+
}
121+

‎String/a.out‎

22.7 KB
Binary file not shown.

‎String/input.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Hello I am Shreyashish Sengupta
2+
Shreyashish

‎String/output.txt‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
0
2+
0
3+
1
4+
1
5+
2
6+
2
7+
3
8+
3
9+
4
10+
4
11+
0
12+
2
13+
3
14+
0
15+
2

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /