|
|
back to boardWhy wa 18 Posted by valdem 10 Mar 2007 18:07 there is my code: program z1501; Var s,s1,s2:string; i,l,n:longint; p:shortint; st:boolean; begin readln(n); readln(s); readln(s1); s:=s+' '; s1:=s1+' '; s2:=''; i:=1; l:=1; st:=false; while True do begin while ((i<=n)or(l<=n))and not st do begin if (p=-1)and(s[i]='1')and(s[i+1]='1')and(s[i+2]='0')then begin s2:=s2+'11'; inc(i,2); p:=1; break; end; if (p=-1)and(s1[l]='1')and(s1[l+1]='1')and(s1[l+2]='0')then begin s2:=s2+'22'; inc(l,2); p:=1; break; end; if (p=1)and(s[i]='0')and(s[i+1]='0')and(s[i+2]='1')then begin s2:=s2+'11'; inc(i,2); p:=-1; break; end; if (p=1)and(s1[l]='0')and(s1[l+1]='0')and(s1[l+2]='1')then begin s2:=s2+'22'; inc(l,2); p:=-1; break; end; if (p=-1)and(s[i]='1')and(s[i+1]='0')then begin s2:=s2+'1'; inc(i); p:=0; break; end; if (p=-1)and(s1[l]='1')and(s1[l+1]='0')then begin s2:=s2+'2'; inc(l); p:=0; break; end; if (p=1)and(s[i]='0')and(s[i+1]='1')then begin s2:=s2+'1'; inc(i); p:=0; break; end; if (p=1)and(s1[l]='0')and(s1[l+1]='1')then begin s2:=s2+'2'; inc(l); p:=0; break; end; if (p=0)and(s[i]='1')and(s[i+1]='0')then begin s2:=s2+'1'; inc(i); p:=1; break; end; if (p=0)and(s1[l]='1')and(s1[l+1]='0')then begin s2:=s2+'2'; inc(l); p:=1; break; end; if (p=0)and(s[i]='0')and(s[i+1]='1')then begin s2:=s2+'1'; inc(i); p:=-1; break; end; if (p=0)and(s1[l]='0')and(s1[l+1]='1')then begin s2:=s2+'2'; inc(l); p:=-1; break; end; if (p=-1)and(s[i]='1')then begin s2:=s2+'1'; inc(i); p:=0; break; end; if (p=-1)and(s1[l]='1')then begin s2:=s2+'2'; inc(l); p:=0; break; end; if (p=1)and(s[i]='0')then begin s2:=s2+'1'; inc(i); p:=0; break; end; if (p=1)and(s1[l]='0')then begin s2:=s2+'2'; inc(l); p:=0; break; end; if (p=0)and(s[i]='1')then begin s2:=s2+'1'; inc(i); p:=1; break; end; if (p=0)and(s1[l]='1')then begin s2:=s2+'2'; inc(l); p:=1; break; end; if (p=0)and(s[i]='0')then begin s2:=s2+'1'; inc(i); p:=-1; break; end; if (p=0)and(s1[l]='0')then begin s2:=s2+'2'; inc(l); p:=-1; break; end; st:=true; end; if (length(s2)=2*n)or st then break; end; if length(s2)=2*n then writeln(s2) else writeln('Impossible'); end. |
|
|