my code stock.com

DFS~~

Snippet options

Download: Download snippet as 142-clocks.txt.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

{
 ID:leaspos1
 PROG:clocks
 LANG:PASCAL
}
const
        way : array[1..9] of string=('abde','abc','bcef','adg','bdefh','cfi','degh','ghi','efhi');
        prime=55566677;
 
type
        int = longint;
 
var
        i,j,num,tmp,val       : int;
        ans,t,s               : string;
        done                  : boolean=false;
        table                 : array[1..9,1..9] of int;
        len,used              : array[1..9] of int;
  
procedure search(pos:int);
var
        i,j : int;
        
begin
        if s = '444444444' then
        begin
                done := true;
                exit;
        end;
        if pos=10 then exit;
        for i := 0 to 3 do
        begin
                for j := 1 to len[pos] do
                begin
                        tmp :=table[pos][j];
                        s[tmp] := chr(ord(s[tmp])+i);
                        if s[tmp] > '4' then
                         if s[tmp]='5' then s[tmp]:='1'
                          else if s[tmp]='6' then s[tmp]:='2'
                           else if s[tmp]='7' then s[tmp]:='3';
                end;
                search(pos+1);
                if done then
                begin
                        for j:=1 to i do
                         ans := chr(pos+ord('0'))+' '+ans;
                        exit;
                end;
                for j:=1 to len[pos] do 
                begin
                        tmp    := table[pos][j];
                        s[tmp] := chr(ord(s[tmp])-i);
                        if s[tmp] <'1' then 
                         if s[tmp] = '0' then s[tmp]:='4'
                          else if s[tmp]='/' then s[tmp]:='3'
                           else if s[tmp]='.' then s[tmp]:='2';
                end;
        end;
end;
 
begin
        assign(input,'clocks.in');   reset(input);
        assign(output,'clocks.out'); rewrite(output);
        fillchar(len,sizeof(len),0);  fillchar(used,sizeof(used),0);
        for i := 1 to 9 do
        begin
                len[i] := length(way[i]);
                for j  := 1 to len[i] do
                 table[i][j] := ord(way[i][j])-ord('a')+1;      
                read(num);
                if i mod 3 = 0 then readln;
                s := s+chr(ord('0')+num div 3);
        end;
        search(1);
        writeln(copy(ans,1,length(ans)-1));
        close(input);close(output);
end.

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.