-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathirepeatmyself.cpp
More file actions
37 lines (35 loc) · 957 Bytes
/
irepeatmyself.cpp
File metadata and controls
37 lines (35 loc) · 957 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
/*
* Author: Maanas Karwa
* It is ok to share my code anonymously for educational purposes
* */
#include <bits/stdc++.h>
using namespace std;
const int mxn=200;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin.exceptions(std::istream::failbit);
cin >> n;
string s;
getline(cin, s); // scan entire line super helpful do not forget
while (n--) {
getline(cin, s);
int length = s.length();
for (int i = 1; i <= length; i++) { // brute force, try all lengths from 1 till string length
bool works = true;
string candidate = s.substr(0,i);
int candidateLen = candidate.length();
for (int j = 0; j < length; j++) {
if (s[j] != candidate[j % candidateLen]) { // character in original string does not match corresponding char in pattern
works = false;
break;
}
}
if (works) {
cout << i << "\n";
break;
}
}
}
}