分析
直接依题意枚举,注意:每个单词的前缀长度并不一定相等。
程序:
var
n,i,j,l,k,bz:longint;
a:array[0..100]of string;
s:array[0..100]of longint;
function check(x,y:string;z:longint):longint;
begin
if copy(x,1,z)<>copy(y,1,z) then exit(0) else exit(1);
end;
begin
assign(input,'abbreviate.in');
reset(input);
assign(output,'abbreviate.out');
rewrite(output);
readln(n);
for i:=1 to n do
readln(a[i]);
fillchar(s,sizeof(s),0);
for i:=1 to n do
begin
l:=length(a[i]);
for k:=1 to l do
begin
bz:=0;
for j:=1 to n do
if (i<>j)and(check(a[i],a[j],k)=1) then
begin
bz:=1;break;
end;
if bz=0 then begin s[i]:=k;break; end;
end;
end;
for i:=1 to n do
writeln(copy(a[i],1,s[i]));
close(input);
close(output);
end.