Am nevoie de problema asta de pe pbinfo!!!!! (Clasa a X-a) Vă rog..... dau coroana și 50p
Răspunsuri la întrebare
#include <bits/stdc++.h>
#define DAU ios::sync_with_stdio(false); fin.tie(0); fout.tie(0);
#define PLEC fin.close(); fout.close(); return 0;
using namespace std;
ifstream fin("kps.in");
ofstream fout("kps.out");
vector<string> v[1005];
int cer, l, k, last;
bool ok;
inline int KPS(string s)
{
l = static_cast<int>(s.size());
for (int p = l - 1; p; --p)
{
ok = true;
for (int i = 0; i < p; ++i)
if (s[i] != s[l - p + i])
ok = false;
if (ok)
return p;
}
return 0;
}
string s;
int main()
{
DAU
fin >> cer;
if (cer == 1)
{
fin >> s;
fout << KPS(s);
PLEC
}
while (fin >> s)
{
k = KPS(s);
last = max(last, k);
v[k].emplace_back(s);
}
for (int i = 0; i <= last; ++i)
{
sort(v[i].begin(), v[i].end());
fout << v[i].size() << ' ';
for (const string& s : v[i])
fout << s << ' ';
fout << '\n';
}
PLEC
}