#include<bits/stdc++.h>
using namespace std;
string c;
bool cmp(string &a,string &b)
{
int cnt1=a.size(),cnt2=b.size();
for(int i=0;i<(int)a.size();i++)
if(a[i]!=c[i])
cnt1=i;
for(int i=0;i<(int)b.size();i++)
if(b[i]!=c[i])
cnt2=i;
if(cnt1==cnt2) return a<b;
return cnt1<cnt2;
}
int main()
{
int n;
int mx=0;
cin>>n;
string s[n];
for(int i=0;i<n;i++)
{
cin>>s[i];
if((int)s[i].size()>mx||((int)s[i].size()==mx&&s[i]>c))
mx=(int)s[i].size(),c=s[i];
}
vector<char>ans;
sort(s,s+n,cmp);
for(int i=0;i<(int)s[0].size();i++)
ans.push_back(s[0][i]);
ans.push_back('p');
for(int i=1;i<n;i++)
{
if(s[i-1].size()>s[i].size())
for(int i=0;i<(int)s[i-1].size()-(int)s[i].size();i++)
ans.push_back('-');
int sz=min((int)s[i-1].size(),(int)s[i].size());
int k=0;
for(;k<sz;k++)
if(s[i-1][k]!=s[i][k])
break;
k--;
for(int j=k;j<sz-1;j++)
ans.push_back('-');
k++;
for(;k<(int)s[i].size();k++)
ans.push_back(s[i][k]);
ans.push_back('P');
}
cout<<ans.size()<<endl;
for(auto i:ans)
cout<<i<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
608 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
1112 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
2380 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
2056 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |