题目链接:点击打开链接
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
string st[500010];
int l[500010];
int main()
{
int n,i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
{
cin>>st[i];
l[i]=st[i].length();
}
for(i=n-1;i>0;i--)
{
for(j=1;j<l[i]&&j<l[i-1];j++)
{
if((st[i][j]-'a')>(st[i-1][j]-'a'))
break;
else if((st[i][j]-'a')==(st[i-1][j]-'a'))
continue;
else
{
st[i-1][j]='\0';
break;
}
}
//printf("%d\n",j);
if(j==l[i])
st[i-1][j]='\0';
continue;
}
for(i=0;i<n;i++)
{
j=0;
while(st[i][j]!='\0')
{
printf("%c",st[i][j]);
j++;
}
printf("\n");
}
return 0;
}