Cele mai bune solutii
pentru problema "Codificare"
(ziua1, problema3)
Punctaj Maxim : 35 puncte
Solutii :
Anghelache Florin - Prahova -35 puncte
Marina Constantin - Alba -35 puncte
Nechita Onu - Olt -35 puncte
Patrascu Mihai - Dolj -35 puncte
Trifan Ionut - Buzau -35 puncte
Gheorghe Andrei - Bucuresti -35 puncte
Chiriliuc Adal - Suceava -35 puncte
Tuhut Adrian - Galati -35 puncte
Tuhut Adrian - Galati
Comisia Centrala
Fisierele de teste
Program realizat de elevul Anghelache Florin - rezultat final : premiu III - 87 puncte
program codificare; uses crt; var mi,mf:array[1..10,1..10] of char; z,i,j,n:integer; f:text; aux:array[1..5] of 1..5; rot:array[1..5] of 0..1; l:array[1..500] of char; sir:string; procedure roteste; var r:char; k:integer; begin for k:=1 to 5 do begin sir:=''; case aux[k] of 1:begin for i:=4 to 7 do sir:=sir+mf[1,i]; for i:=2 to 3 do sir:=sir+mf[i,7]; for i:=7 downto 4 do sir:=sir+mf[4,i]; for i:=3 downto 2 do sir:=sir+mf[i,4]; end; 2:begin for i:=1 to 4 do sir:=sir+mf[4,i]; for i:=5 to 6 do sir:=sir+mf[i,4]; for i:=4 downto 1 do sir:=sir+mf[7,i]; for i:=6 downto 5 do sir:=sir+mf[i,1]; end; 3:begin for i:=4 to 7 do sir:=sir+mf[4,i]; for i:=5 to 6 do sir:=sir+mf[i,7]; for i:=7 downto 4 do sir:=sir+mf[7,i]; for i:=6 downto 5 do sir:=sir+mf[i,4]; end; 4:begin for i:=7 to 10 do sir:=sir+mf[4,i]; for i:=5 to 6 do sir:=sir+mf[i,10]; for i:=10 downto 7 do sir:=sir+mf[7,i]; for i:=6 downto 5 do sir:=sir+mf[i,7]; end; 5:begin for i:=4 to 7 do sir:=sir+mf[7,i]; for i:=8 to 9 do sir:=sir+mf[i,7]; for i:=7 downto 4 do sir:=sir+mf[10,i]; for i:=9 downto 8 do sir:=sir+mf[i,4]; end; end; {aux} case rot[aux[k]] of 1:begin r:=sir[length(sir)]; delete(sir,length(sir),1); sir:=r+sir; end; 0:begin r:=sir[1]; delete(sir,1,1); sir:=sir+r; end; end;{rot} case aux[k] of 1:begin for i:=4 to 7 do begin mf[1,i]:=sir[1]; delete(sir,1,1); end; for i:=2 to 3 do begin mf[i,7]:=sir[1]; delete(sir,1,1); end; for i:=7 downto 4 do begin mf[4,i]:=sir[1]; delete(sir,1,1); end; for i:=3 downto 2 do begin mf[i,4]:=sir[1]; delete(sir,1,1); end; end;{1} 2:begin for i:=1 to 4 do begin mf[4,i]:=sir[1]; delete(sir,1,1); end; for i:=5 to 6 do begin mf[i,4]:=sir[1]; delete(sir,1,1); end; for i:=4 downto 1 do begin mf[7,i]:=sir[1]; delete(sir,1,1); end; for i:=6 downto 5 do begin mf[i,1]:=sir[1]; delete(sir,1,1); end; end;{2} 3:begin for i:=4 to 7 do begin mf[4,i]:=sir[1]; delete(sir,1,1); end; for i:=5 to 6 do begin mf[i,7]:=sir[1]; delete(sir,1,1); end; for i:=7 downto 4 do begin mf[7,i]:=sir[1]; delete(sir,1,1); end; for i:=6 downto 5 do begin mf[i,4]:=sir[1]; delete(sir,1,1); end; end;{3} 4:begin for i:=7 to 10 do begin mf[4,i]:=sir[1]; delete(sir,1,1); end; for i:=5 to 6 do begin mf[i,10]:=sir[1]; delete(sir,1,1); end; for i:=10 downto 7 do begin mf[7,i]:=sir[1]; delete(sir,1,1); end; for i:=6 downto 5 do begin mf[i,7]:=sir[1]; delete(sir,1,1); end; end;{4} 5:begin for i:=4 to 7 do begin mf[7,i]:=sir[1]; delete(sir,1,1); end; for i:=8 to 9 do begin mf[i,7]:=sir[1]; delete(sir,1,1); end; for i:=7 downto 4 do begin mf[10,i]:=sir[1]; delete(sir,1,1); end; for i:=9 downto 8 do begin mf[i,4]:=sir[1]; delete(sir,1,1); end; end;{5} end; {aux} end; {for} end; procedure cauta(c:char); var i,j:integer; begin for i:=1 to 10 do for j:=1 to 10 do if mi[i,j]=c then write(f,mf[i,j]); end; begin clrscr; fillchar(mi,sizeof(mi),'0'); mi[1,4]:='C';mi[1,5]:='D';mi[1,6]:='E';mi[1,7]:='F';mi[2,4]:='B';mi[2,7]:='G';mi[3,4]:='A'; mi[3,7]:='H';mi[4,1]:='a';mi[4,2]:='b';mi[4,3]:='c';mi[4,4]:='d';mi[4,5]:='e';mi[4,6]:='f'; mi[4,7]:='g';mi[4,8]:='h';mi[4,9]:='i';mi[4,10]:='j';mi[5,1]:='u';mi[5,4]:='U';mi[5,7]:='Z'; mi[5,10]:='k';mi[6,1]:='w';mi[6,4]:='T';mi[6,7]:='J';mi[6,10]:='l';mi[7,1]:='v';mi[7,2]:='x'; mi[7,3]:='t';mi[7,4]:='s';mi[7,5]:='r';mi[7,6]:='q';mi[7,7]:='p';mi[7,8]:='o';mi[7,9]:='n'; mi[7,10]:='m';mi[8,4]:='R';mi[8,7]:='K';mi[9,4]:='Q';mi[9,7]:='L';mi[10,4]:='P';mi[10,5]:='O'; mi[10,6]:='N';mi[10,7]:='M'; for i:=1 to 10 do for j:=1 to 10 do mf[i,j]:=mi[i,j]; assign(f,'cod.in');reset(f); for i:=1 to 5 do read(f,aux[i]); readln(f); for i:=1 to 5 do read(f,rot[aux[i]]); readln(f);i:=0; while not(eoln(f)) do begin inc(i); read(f,l[i]); end; close(f); n:=i; assign(f,'cod.out');rewrite(f); for z:=1 to n do begin roteste; cauta(l[z]); end; close(f); end.
Program realizat de elevul Tuhut Adrian - rezultat final : premiu III - 97 puncte
#include<stdio.h> #include<conio.h> #include<string.h> int ord[6],misc[6],lung,y; char sir[600]; char p1[13]={"CDEFGHgfedAB"},p2[13]={"abcdUTstxvwu"},p3[13]={"defgZJpqrsTU"}; char p4[13]={"ghijklmnopJZ"},p5[13]={"srqpKLMNOPQR"}; char pp1[13]={"CDEFGHgfedAB"},pp2[13]={"abcdUTstxvwu"},pp3[13]={"defgZJpqrsTU"}; char pp4[13]={"ghijklmnopJZ"},pp5[13]={"srqpKLMNOPQR"}; void rotd(char t[20]) { int i; char ch; ch=t[11]; for(i=11;i>0;i--) t[i]=t[i-1]; t[0]=ch; } void rots(char t[20]) { int i; char ch; ch=t[0]; for(i=0;i<11;i++) t[i]=t[i+1]; t[11]=ch; } void inloc1() { p2[3]=p1[9]; p3[0]=p1[9]; p3[1]=p1[8]; p3[2]=p1[7]; p3[3]=p1[6]; p4[0]=p1[6]; } void inloc2() { p1[9]=p2[3]; p3[0]=p2[3]; p3[11]=p2[4]; p3[10]=p2[5]; p3[9]=p2[6]; p5[0]=p2[6]; } void inloc3() { p1[6]=p3[3]; p1[7]=p3[2]; p1[8]=p3[1]; p1[9]=p3[0]; p2[3]=p3[0]; p2[4]=p3[11]; p2[5]=p3[10]; p2[6]=p3[9]; p4[0]=p3[3]; p4[11]=p3[4]; p4[10]=p3[5]; p4[9]=p3[6]; p5[0]=p3[9]; p5[1]=p3[8]; p5[2]=p3[7]; p5[3]=p3[6]; } void inloc4() { p1[6]=p4[0]; p3[3]=p4[0]; p3[4]=p4[11]; p3[5]=p4[10]; p3[6]=p4[9]; p5[3]=p4[9]; } void inloc5() { p2[6]=p5[0]; p3[9]=p5[0]; p3[8]=p5[1]; p3[7]=p5[2]; p3[6]=p5[3]; p4[9]=p5[3]; } void main() { FILE *f=fopen("cod.in","r"),*g=fopen("cod.out","w"); int i,j,k,test=0; clrscr(); for(i=1;i<=5;i++) fscanf(f,"%d",&ord[i]); for(i=1;i<=5;i++) fscanf(f,"%d",&misc[i]); fscanf(f,"%s",&sir); lung=strlen(sir); for(y=0;y<lung;y++) { test=0; for(k=1;k<=5;k++) { if(ord[k]==1) { if(misc[k]==1) { rotd(p1); inloc1(); } else { rots(p1); inloc1(); } } if(ord[k]==2) { if(misc[k]==1) { rotd(p2); inloc2(); } else { rots(p2); inloc2(); } } if(ord[k]==3) { if(misc[k]==1) { rotd(p3); inloc3(); } else { rots(p3); inloc3(); } } if(ord[k]==4) { if(misc[k]==1) { rotd(p4); inloc4(); } else { rots(p4); inloc4(); } } if(ord[k]==5) { if(misc[k]==1) { rotd(p5); inloc5(); } else { rots(p5); inloc5(); } } } for(j=0;j<12;j++) if(pp1[j]==sir[y]) { if(test==0) fprintf(g,"%c",p1[j]); test=1; } for(j=0;j<12;j++) if(pp2[j]==sir[y]) { if(test==0) fprintf(g,"%c",p2[j]); test=1; } for(j=0;j<12;j++) if(pp3[j]==sir[y]) { if(test==0) fprintf(g,"%c",p3[j]); test=1; } for(j=0;j<12;j++) if(pp4[j]==sir[y]) { if(test==0) fprintf(g,"%c",p4[j]); test=1; } for(j=0;j<12;j++) if(pp5[j]==sir[y]) { if(test==0) fprintf(g,"%c",p5[j]); test=1; } } }
Program realizat de Comisia Centrala a Olimpiadei Nationale de Informatica
{program comisie - tratarea
erorilor incompleta- Prof. Ioana Tantas
- Prof.
Rodica Pintea }
{program comisie - tratarea erorilor incompleta- Ioana+Rodica} program p1; var n,m,i,j,k,len:longint; f:text; nume:string; a:array[1..1000]of integer; procedure error(i:byte); begin rewrite(f); writeln(f,'NU'); writeln(f,i); close(f); halt end; begin {Citeste datele de intrare} assign(f,'poza.in'); reset(f); m:=0; while not seekeof(f) do begin m:=m+1; read(f,a[m]); end; close(f); n:=0; i:=1; while i<=m do if a[i]=-1 then begin n:=n+a[i+2];i:=i+3 end else begin n:=n+1;i:=i+1 end; len:=round(sqrt(n)); assign(f,'poza.out'); if sqr(len)<>n then error(5); rewrite(f); {Scrie dimensiunea matricii} writeln(f,len); i:=1;k:=0; while i<=m do begin if a[i]="-1" then begin if not(a[i+1] in [0,1]) then error(6); if a[i+2]<="1" then error(a[i+1]); for j:="1" to a[i+2] do begin inc(k); write(f,a[i+1]); if k="len" then begin writeln(f);k:="0" end; end; i:="i+3" end else if not(a[i] in [0,1]) then error(5) else begin write(f,a[i]); i:="i+1;k:=k+1;" if k="len" then begin writeln(f);k:="0" end end; end; close(f); end.
Fisierele de teste :
Test 1 :
-1 0 4 -1 1 2 0 1 0
Test 2 :
0 1 -1 0 4 1 0 -1 1 4 0 -1 1 5 0 1 -1 0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1 0 1 0 1 0 1 0 1 0
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
0 1 0 1
Test 4 :
1
Test 5 :
-1 0 16
Test 6 :
-1 3 2 0 1
Test 7 :
0 1 -1 0 1 1
Test 8 :
-1 1 1 -1 0 3
Test 9 :
1 1
Test 10 :
0 0
Test 11 :
1 -1 0 5
Test 12 :
-1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1
1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1
800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0 800 -1 1 800 -1 0
800 -1 1 800 -1 0 800 -1 1 800