fork download
  1. program scopa;
  2. type carta = record
  3. numero:longint;
  4. seme:char
  5. end;
  6. coppie = record
  7. somma:longint;
  8. indice1:longint;
  9. indice2:longint;
  10. end;
  11. var
  12. line: ansistring;
  13. i,j, h,w,z, tot, som, number, ricordaidscopa,ricordaid2, idsetteincoppia,ricordaidcoppiasette,idmanosette, idtablesette, ricordaidternasette, ricordasememano, ricordasemetable, ricordanumero, ricordaterna, ricordacoppia, ricordasingolo: longint;
  14. suit: char;
  15. mano, table: array[1..4] of carta;
  16. prendodue : array[1..6] of coppie;
  17. settebinmano, settebintable, setteinmano,setteintable,setteincoppia, setteinterna,coppiasette, fattoscopa,ternasette, trovatosette,trovatosette1, trovatosette2, laterna, coppia, singolo: boolean;
  18. terna:array [1..4] of longint;
  19.  
  20. procedure readcard(var s: ansistring; var number: longint; var suit: char);
  21. begin
  22. if (s[1] = '1') and (s[2] = '0') then
  23. begin
  24. number := 10;
  25. suit := s[3];
  26. s := copy(s, 5, length(s));
  27. end else begin
  28. number := ord(s[1]) - ord('0');
  29. if ord(s[2])<>32 then
  30. begin
  31. suit := s[2];
  32. s := copy(s, 4, length(s));
  33. end
  34. else
  35. begin
  36. suit := s[2+1];
  37. s := copy(s, 4+1, length(s));
  38. end;
  39. end;
  40. end;
  41.  
  42.  
  43.  
  44. begin
  45. {
  46.   uncomment the following lines if you want to read/write from files
  47.   assign(input, 'input.txt'); reset(input);
  48.   assign(output, 'output.txt'); rewrite(output);
  49. }
  50. settebinmano:=false; settebintable:=false; ternasette:=false;setteinmano:=false; coppiasette:=false; setteintable:=false;fattoscopa:=false; trovatosette1:=false; trovatosette2:=false; setteinterna:=false; setteincoppia:=false;
  51. readln(line);
  52. for i:=1 to 3 do
  53. begin
  54. { card in hand }
  55. readcard(line, number, suit);
  56. writeln (line);
  57. mano[i].numero:=number;
  58. mano[i].seme:=suit;
  59. if (number=7) and (suit='G') then settebinmano:=true;
  60. { use number and suit }
  61. end;
  62.  
  63. readln(line);
  64. tot:=0;
  65. for i:=1 to 4 do
  66. begin
  67. { card on table }
  68. readcard(line, number, suit);
  69. writeln(line);
  70. table[i].numero:=number;
  71. table[i].seme:=suit;
  72. tot:=tot+number;
  73. if (number=7) and (suit='G') then settebintable:=true;
  74. { use number and suit }
  75. end;
  76. for i:=1 to 3 do if mano[i].numero=tot then begin fattoscopa:=true; ricordaidscopa:=i; end;
  77. h:=1; for i:=1 to 4 do begin terna[h]:=tot-table[i].numero; h:=h+1; end;
  78. for i:=1 to 4 do if terna[i]=7 then begin ternasette:=true; ricordaidternasette:=i; end;
  79. for i:=1 to 3 do if mano[i].numero=7 then begin setteinmano:=true; idmanosette:=i; end;
  80. for i:=1 to 4 do if table[i].numero=7 then begin setteintable:=true; idtablesette:=i; end;
  81. h:=0;
  82. for i:= 1 to 3 do
  83. begin
  84. som:=0;
  85. for j:=i+1 to 4 do
  86. begin
  87. h:=h+1;
  88. som:=table[i].numero+table[j].numero;
  89. if table[j].numero= 7 then begin setteincoppia:=true; idsetteincoppia:=h; end;
  90. prendodue[h].somma:=som;
  91. prendodue[h].indice1:=i;
  92. prendodue[h].indice2:=j;
  93. end;
  94. end;
  95. for i:=1 to 6 do if prendodue[i].somma=7 then begin coppiasette:=true; ricordaidcoppiasette:=i; end;
  96. if settebinmano=true then
  97. begin if setteintable=true then writeln ('7','G',' ','7',table[idtablesette].seme)
  98. else
  99. begin
  100. 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)
  101. else
  102. if ternasette=true then begin write (mano[idmanosette].numero, mano[idmanosette].seme,' ');
  103. for z:=1 to 4 do if z<>ricordaidternasette then write (table[z].numero, table[z].seme,' '); writeln; end;
  104. end
  105. end
  106. else if settebintable=true then
  107. begin for i:=1 to 3 do if mano[i].numero=7 then writeln ('7','G',' ','7',mano[i].seme); end
  108.  
  109. else if fattoscopa=true then begin write(mano[ricordaidscopa].numero,mano[ricordaidscopa].seme,' ');
  110. for j:=1 to 4 do write(table[j].numero,table[j].seme,' '); writeln;end
  111. else if (setteinmano=true) then begin if setteintable=true then writeln (mano[idmanosette].numero, mano[idmanosette].seme,' ',table[idtablesette].numero, table[idtablesette].seme)
  112. else
  113. begin
  114. 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)
  115. else
  116. if ternasette=true then begin write (mano[idmanosette].numero, mano[idmanosette].seme,' ');
  117. for z:=1 to 4 do if z<>ricordaidternasette then write (table[z].numero, table[z].seme,' '); writeln; end;
  118. end;
  119. end
  120. 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
  121. else
  122. begin
  123. laterna:=false; coppia:=false; singolo:=false;
  124. for i:=1 to 3 do
  125. for j:=1 to 4 do if mano[i].numero=terna[j] then begin ricordanumero:=i; ricordaterna:=j; laterna:=true; end;
  126. if laterna=false then for i:=1 to 3 do
  127. for j:=1 to 6 do if mano[i].numero=prendodue[j].somma then begin ricordanumero:=i; ricordacoppia:=j;coppia:=true; end;
  128. if ((laterna=false) and (coppia=false)) then for i:=1 to 3 do
  129. for j:=1 to 4 do if mano[i].numero=table[j].numero then begin ricordanumero:=i; ricordasingolo:=j;singolo:=true; end;
  130. if laterna=true then begin write (mano[ricordanumero].numero,mano[ricordanumero].seme,' ');
  131. for z:=1 to 4 do if z<>ricordaterna then write (table[z].numero, table[z].seme,' '); writeln;
  132. end
  133. else
  134. if coppia=true then begin write (mano[ricordanumero].numero,mano[ricordanumero].seme,' ');
  135. write(table[prendodue[ricordacoppia].indice1].numero, table[prendodue[ricordacoppia].indice1].seme,' ',table[prendodue[ricordacoppia].indice2].numero, table[prendodue[ricordacoppia].indice2].seme); writeln;
  136. end
  137. else if singolo=true then writeln (mano[ricordanumero].numero,mano[ricordanumero].seme,' ',table[ricordasingolo].numero,table[ricordasingolo].seme );
  138. end;
  139.  
  140. end.
  141.  
Success #stdin #stdout 0.01s 5280KB
stdin
5 G 4 C 6 S
4 G 3 C 4 S 1 C
stdout
4 C 6 S
6 S

3 C 4 S 1 C
4 S 1 C
1 C

4C 3C 1C