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, ricordaidcoppiasette,idmanosette, idtablesette, ricordaidternasette: longint;
  14. suit: char;
  15. mano, table: array[1..4] of carta;
  16. prendodue : array[1..6] of coppie;
  17. settebinmano, settebintable, setteinmano,setteintable,coppiasette, fattoscopa,ternasette, trovatosette,trovatosette1, trovatosette2: 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;
  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. prendodue[h].somma:=som;
  90. prendodue[h].indice1:=i;
  91. prendodue[h].indice2:=j;
  92. end;
  93. end;
  94. for i:=1 to 6 do if prendodue[i].somma=7 then begin coppiasette:=true; ricordaidcoppiasette:=i; end;
  95. if settebinmano=true then
  96. begin if setteintable=true then writeln ('7','G',' ','7',table[idtablesette].seme)
  97. else
  98. begin
  99. 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)
  100. else
  101. if ternasette=true then begin write (mano[idmanosette].numero, mano[idmanosette].seme,' ');
  102. for z:=1 to 4 do if z<>ricordaidternasette then write (table[z].numero, table[z].seme,' '); writeln; end;
  103. end
  104. end
  105. else if settebintable=true then
  106. begin for i:=1 to 3 do if mano[i].numero=7 then writeln ('7','G',' ','7',mano[i].seme); end
  107. else if fattoscopa=true then begin write(mano[ricordaidscopa].numero,mano[ricordaidscopa].seme,' ');
  108. for j:=1 to 4 do write(table[j].numero,table[j].seme,' '); writeln;end
  109. else if (setteinmano=true) then begin if setteintable=true then writeln (mano[idmanosette].numero, mano[idmanosette].seme,' ',table[idtablesette].numero, table[idtablesette].seme)
  110. else
  111. begin
  112. 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)
  113. else
  114. if ternasette=true then begin write (mano[idmanosette].numero, mano[idmanosette].seme,' ');
  115. for z:=1 to 4 do if z<>ricordaidternasette then write (table[z].numero, table[z].seme,' '); writeln; end;
  116. end;
  117. end;
  118.  
  119. end.
  120.  
Success #stdin #stdout 0s 5280KB
stdin
5G 4C 8S
4G 1G 1S 2C
stdout
4C 8S
8S

1G 1S 2C
1S 2C
2C

8S 4G 1G 1S 2C