-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKps.cpp
More file actions
66 lines (56 loc) · 1.21 KB
/
Copy pathKps.cpp
File metadata and controls
66 lines (56 loc) · 1.21 KB
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
#include <bits/stdc++.h>
using namespace std;
ifstream fin("kps.in");
ofstream fout("kps.out");
constexpr int NMAX = 1e4 + 5;
int c;
string s;
vector<pair<int, multiset<string>>> vect(NMAX);
int kps(const string s) {
int k = 0;
int kmax = 0;
string pref;
string suff;
for (size_t i = 0, j = s.size() - 1; i < s.size() - 1; i++, j--) {
k++;
suff += s[j];
pref += s[i];
reverse(suff.begin(), suff.end());
// fout << pref << '\n' << suff << '\n';
if (suff == pref) {
kmax = k;
}
reverse(suff.begin(), suff.end());
}
return kmax;
}
void task_1() {
fin >> s;
fout << kps(s) << '\n';
}
void task_2() {
int kmax = 0;
while (fin >> s) {
int k = kps(s);
kmax = max(kmax, k);
vect[k].first++;
vect[k].second.insert(s);
}
for (size_t i = 0; i <= kmax; i++) {
fout << vect[i].first << ' ';
for (auto it : vect[i].second) {
fout << it << ' ';
}
fout << '\n';
}
}
int main() {
fin >> c;
switch (c) {
case 1: task_1(); break;
case 2: task_2(); break;
}
fin.close();
fout.close();
return 0;
}