const inf=maxlongint;
const inf1='123';
var
a:array[0..80,0..80] of string;
n,m,i,j,a1,a2:longint;
s,t:string;
ch:char;
function max(a,b:longint):longint;
begin
max:=a;
if a<b then max:=b;
end;
function len(i,j:longint):longint;
begin
if a[i,j]=inf1 then len:=inf else len:=length(a[i,j]);
end;
begin
assign(input,'input.txt'); reset(input);
assign(output,'output.txt'); rewrite(output);
n:=0; m:=0; s:=''; t:='';
while not eoln do
begin
read(ch);
if (ch in['A'..'Z'])or(ch in['a'..'z'])or(ch in['?','*']) then
begin
inc(n); s:=s+ch;
end;
end; readln;
while not eoln do
begin
read(ch);
if (ch in['A'..'Z'])or(ch in['a'..'z'])or(ch in['?','*']) then
begin
inc(m); t:=t+ch;
end;
end;
// read(s); n:=length(s);
// read(t); m:=length(t);
a[0,0]:=''; a[0,1]:=''; a[1,0]:='';
for i:=2 to max(n,m) do begin a[i,0]:=inf1; a[0,i]:=inf1; end;
for i:=1 to n do
begin
for j:=1 to m do
begin
if (s[i]='*')and(t[j]='*') then
begin
a1:=len(i,j-1);
a2:=len(i-1,j);
if (a1<a2) then a[i,j]:=a[i,j-1] else a[i,j]:=a[i-1,j];
end else
if (s[i]='*')or(t[j]='*') then
begin
ch:=s[i];
if (ch='*')or(ch='?') then ch:=t[j];
if (ch='*')or(ch='?') then ch:='A';
a1:=len(i-1,j);
a2:=len(i,j-1);
if a1<a2 then a[i,j]:=a[i-1,j]+ch else
begin
a[i,j]:=a[i,j-1];
if (a[i,j][length(a[i,j])]<>ch)and(a[i,j]<>inf1) then a[i,j]:=a[i,j]+ch;
end;
end else
if ((s[i]=t[j])or(s[i]='?')or(t[j]='?')) then
begin
ch:=s[i];
if ch='?' then ch:=t[j];
if ch='?' then ch:='A';
a[i,j]:=a[i-1,j-1]+ch;
end else a[i,j]:=inf1;
end;
end;
if a[n,m]=inf1 then writeln('No solution!') else writeln(a[n,m]);
close(input); close(output);
end. |