fork download
program scopa;
type carta = record
                   numero:longint;
                   seme:char
                end;
     coppie = record
                   somma:longint;
                   indice1:longint;
                   indice2:longint;
                end;            
var
    line: ansistring;
    i,j, h,w,z, tot, som, number, ricordaidscopa,ricordaid2, idsetteincoppia,ricordaidcoppiasette,idmanosette, idtablesette, ricordaidternasette,  ricordasememano, ricordasemetable, ricordanumero, ricordaterna, ricordacoppia, ricordasingolo: longint;
    suit: char;
    mano, table: array[1..4] of carta;
    prendodue : array[1..6] of coppie;
    settebinmano, settebintable, setteinmano,setteintable,setteincoppia, setteinterna,coppiasette, fattoscopa,ternasette, trovatosette,trovatosette1, trovatosette2, laterna, coppia, singolo: boolean;
    terna:array [1..4] of longint;
    
procedure readcard(var s: ansistring; var number: longint; var suit: char);
begin
    if (s[1] = '1') and (s[2] = '0') then
    begin
        number := 10;
        suit := s[3];
        s := copy(s, 5, length(s));
    end else begin
        number := ord(s[1]) - ord('0');
        if ord(s[2])<>32 then 
                         begin
                          suit := s[2];
                          s := copy(s, 4, length(s));
                         end  
                         else
                          begin
                            suit := s[2+1];
                            s := copy(s, 4+1, length(s));
                          end;  
    end;
end;



begin
{
    uncomment the following lines if you want to read/write from files
    assign(input,  'input.txt');  reset(input);
    assign(output, 'output.txt'); rewrite(output);
}
    settebinmano:=false; settebintable:=false; ternasette:=false;setteinmano:=false; coppiasette:=false; setteintable:=false;fattoscopa:=false; trovatosette1:=false; trovatosette2:=false; setteinterna:=false; setteincoppia:=false;
    readln(line);
    for i:=1 to 3 do
    begin
        { card in hand }
        readcard(line, number, suit);
        writeln (line);
        mano[i].numero:=number;
        mano[i].seme:=suit;
        if (number=7) and (suit='G') then settebinmano:=true;
        { use number and suit }
    end;

    readln(line);
    tot:=0; 
    for i:=1 to 4 do
    begin
        { card on table }
        readcard(line, number, suit);
        writeln(line);
        table[i].numero:=number;
        table[i].seme:=suit;
        tot:=tot+number;
        if (number=7) and (suit='G') then settebintable:=true;
        { use number and suit }
    end;
    for i:=1 to 3 do if mano[i].numero=tot then begin fattoscopa:=true; ricordaidscopa:=i; end;
    h:=1; for i:=1 to 4 do begin terna[h]:=tot-table[i].numero; h:=h+1; end;
    for i:=1 to 4 do if terna[i]=7 then begin ternasette:=true; ricordaidternasette:=i; end;
    for i:=1 to 3 do if mano[i].numero=7 then begin setteinmano:=true; idmanosette:=i; end;
    for i:=1 to 4 do if table[i].numero=7 then begin setteintable:=true; idtablesette:=i; end;
    h:=0;
    for i:= 1 to 3 do
                begin
                  som:=0;
                  for j:=i+1 to 4 do
                              begin 
                                 h:=h+1;
                                 som:=table[i].numero+table[j].numero;
                                 if table[j].numero= 7 then begin setteincoppia:=true; idsetteincoppia:=h; end;
                                 prendodue[h].somma:=som;
                                 prendodue[h].indice1:=i;
                                 prendodue[h].indice2:=j;
                               end;
                end; 
    for i:=1 to 6 do if prendodue[i].somma=7 then  begin coppiasette:=true; ricordaidcoppiasette:=i; end;           
    if settebinmano=true then 
                          begin    if setteintable=true then  writeln ('7','G',' ','7',table[idtablesette].seme)
                                                       else
                                                         begin
                                                            if coppiasette=true then writeln (mano[idmanosette].numero, mano[idmanosette].seme,' ',table[prendodue[ricordaidcoppiasette].indice1].numero, table[prendodue[ricordaidcoppiasette].indice1].seme,' ',table[prendodue[ricordaidcoppiasette].indice2].numero, table[prendodue[ricordaidcoppiasette].indice2].seme)
                                                                                else
                                                                                     if ternasette=true then  begin write (mano[idmanosette].numero, mano[idmanosette].seme,' ');
                                                                                                                    for z:=1 to 4  do if z<>ricordaidternasette then write (table[z].numero, table[z].seme,' '); writeln; end;
                                                         end 
                          end    
    else if settebintable=true then 
           begin for i:=1 to 3 do if mano[i].numero=7 then writeln ('7','G',' ','7',mano[i].seme); end
                                 
     else if fattoscopa=true then  begin write(mano[ricordaidscopa].numero,mano[ricordaidscopa].seme,' '); 
                                         for j:=1 to 4 do write(table[j].numero,table[j].seme,' '); writeln;end
     else if (setteinmano=true)  then begin if setteintable=true then writeln  (mano[idmanosette].numero, mano[idmanosette].seme,' ',table[idtablesette].numero, table[idtablesette].seme)
                                                                else
                                                                  begin
                                                                     if coppiasette=true then writeln (mano[idmanosette].numero, mano[idmanosette].seme,' ',table[prendodue[ricordaidcoppiasette].indice1].numero, table[prendodue[ricordaidcoppiasette].indice1].seme,' ',table[prendodue[ricordaidcoppiasette].indice2].numero, table[prendodue[ricordaidcoppiasette].indice2].seme)
                                                                                         else
                                                                                            if ternasette=true then  begin write (mano[idmanosette].numero, mano[idmanosette].seme,' ');
                                                                                                                          for z:=1 to 4  do if z<>ricordaidternasette then write (table[z].numero, table[z].seme,' '); writeln; end;
                                                                  end;    
                                      end
      else if setteintable=true then begin if setteincoppia=true then for i:=1 to 3 do if mano[i].numero=prendodue[idsetteincoppia].somma then writeln(mano[i].numero, mano[i].seme,' ',table[prendodue[idsetteincoppia].indice1].numero, table[prendodue[idsetteincoppia].indice1].seme,' ',table[prendodue[idsetteincoppia].indice2].numero, table[prendodue[idsetteincoppia].indice2].seme); end                      
     else 
        begin 
           laterna:=false; coppia:=false; singolo:=false;
           for i:=1 to 3 do
                     for j:=1 to 4 do if mano[i].numero=terna[j] then begin ricordanumero:=i; ricordaterna:=j; laterna:=true; end;
           if laterna=false then for i:=1 to 3 do
                                     for j:=1 to 6 do if mano[i].numero=prendodue[j].somma then begin ricordanumero:=i; ricordacoppia:=j;coppia:=true; end;          
           if ((laterna=false) and (coppia=false)) then for i:=1 to 3 do
                                                          for j:=1 to 4 do if mano[i].numero=table[j].numero then begin ricordanumero:=i; ricordasingolo:=j;singolo:=true; end; 
           if laterna=true then begin  write (mano[ricordanumero].numero,mano[ricordanumero].seme,' ');
                                      for z:=1 to 4  do if z<>ricordaterna then write (table[z].numero, table[z].seme,' '); writeln; 
                               end
                          else 
                              if coppia=true then begin write (mano[ricordanumero].numero,mano[ricordanumero].seme,' ');
                                                        write(table[prendodue[ricordacoppia].indice1].numero, table[prendodue[ricordacoppia].indice1].seme,' ',table[prendodue[ricordacoppia].indice2].numero, table[prendodue[ricordacoppia].indice2].seme); writeln; 
                                                  end
                          else if singolo=true then writeln (mano[ricordanumero].numero,mano[ricordanumero].seme,' ',table[ricordasingolo].numero,table[ricordasingolo].seme );
        end;  
        writeln(setteincoppia);
end.
Success #stdin #stdout 0.01s 5264KB
stdin
5G 4S 8S
2G 1C 7G 2C

stdout
4S 8S
8S

1C 7G 2C
7G 2C
2C

TRUE