ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1015. Test the Difference!

Will you please tell me where I made a mistake?
Posted by SunCat 21 Jan 2003 10:11
Note: mistakes except the input or output file
program Ural1015;
const zh1:array[1..6] of byte=(1,2,4,5,6,3);
      zh2:array[1..6] of byte=(4,6,3,2,5,1);
      maxn=100000;
type arr=array[1..6] of byte;
var n,i,j,m:longint;
    kind:array[1..maxn] of integer;
    kinds:integer;
    oper:arr;
    hash:array[1..maxn] of arr;

function change(t:arr;a,b:integer):arr;
var i,m:integer;
    temp:array[0..1] of arr;
begin
 temp[0]:=t;
 for i:=1 to a do
  for m:=1 to 6 do temp[i mod 2][m]:=temp[(i-1)mod 2][zh1[m]];
 temp[0]:=temp[a mod 2];
 for i:=1 to b do
  for m:=1 to 6 do temp[i mod 2][m]:=temp[(i-1)mod 2][zh2[m]];
 change:=temp[b mod 2];
end;

function find(t:arr;index:longint):integer;
var i,j:integer;
    ok:boolean;
begin
 for i:=1 to index-1 do
  begin
   ok:=true;
   for j:=1 to 6 do
    if t[j]<>hash[i][j] then begin ok:=false;break end;
   if ok then
    begin
     find:=kind[i];
     exit
    end;
  end;
 find:=0;
end;

procedure solve(t:arr;index:longint);
var i,j,lab:integer;
    temp:arr;
begin
  for i:=0 to 3 do
   for j:=0 to 3 do
     begin
      temp:=change(t,i,j);
      lab:=find(temp,index);
      if lab<>0 then
       begin
        kind[index]:=lab;exit
       end;
     end;
  inc(kinds);
  kind[index]:=kinds;
end;

begin
 fillchar(kind,sizeof(kind),0);kinds:=0;
 assign(input,'input.txt');reset(input);
 assign(output,'1015.out');rewrite(output);
 readln(n);
 for i:=1 to n do
  begin
   fillchar(oper,sizeof(oper),0);
   for j:=1 to 6 do read(oper[j]);
   solve(oper,i);
   hash[i]:=oper;
  end;
 writeln(kinds);
 for i:=1 to kinds do
  begin
   j:=1;
   while kind[j]<>i do inc(j);
   write(j);
   for m:=j+1 to n do if kind[m]=i then write(' ',m);
   writeln;
  end;
 close(input);close(output);
end.