【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
用map > dic;模拟就好。
后缀。翻转一下就变成前缀了。
两重循环剔除这种情况不输出就好。
【代码】
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
#include <bits/stdc++.h>
using namespace std;
map <string,vector <string> > dic;
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;
while (T--){
string s;
cin >> s;
int num;
cin >> num;
for (int i = 1;i <= num;i++){
string ts;
cin >> ts;
reverse(ts.begin(),ts.end());
dic[s].push_back(ts);
}
}
cout << dic.size() << endl;
for (auto temp:dic){
vector<string> v = temp.second;
for (int i = 0;i < (int) v.size();i++)
for (int j = 0;j <(int) v.size()-1;j++){
if ((int)v[j].size()>(int)v[j+1].size()){
swap(v[j],v[j+1]);
}
}
set <int> myset;myset.clear();
int len = v.size();
for (int i = 0;i < len;i++)
for (int j = i+1;j < len;j++){
int tlen = v[i].size();
if (v[i]==v[j].substr(0,tlen)){
myset.insert(i);
}
}
cout << temp.first<<' '<<len - (int)myset.size();
for (int i = 0;i < len;i++){
if (myset.count(i)==0){
reverse(v[i].begin(),v[i].end());
cout <<' '<<v[i];
}
}
cout << endl;
}
return 0;
}