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, tot, som, number, ricordaid: longint;
  14. suit: char;
  15. mano, table: array[1..4] of carta;
  16. prendodue : array[1..6] of coppie;
  17. settebinmano, settebintable, fattoscopa, trovatosette: 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; fattoscopa:=false;
  51.  
  52. readln(line);
  53. for i:=1 to 3 do
  54. begin
  55. { card in hand }
  56. readcard(line, number, suit);
  57. writeln (line);
  58. mano[i].numero:=number;
  59. mano[i].seme:=suit;
  60. if (number=7) and (suit='G') then settebinmano:=true;
  61. { use number and suit }
  62. end;
  63.  
  64. readln(line);
  65. tot:=0;
  66. for i:=1 to 4 do
  67. begin
  68. { card on table }
  69. readcard(line, number, suit);
  70. writeln(line);
  71. table[i].numero:=number;
  72. table[i].seme:=suit;
  73. tot:=tot+number;
  74. if (number=7) and (suit='G') then settebintable:=true;
  75. { use number and suit }
  76. end;
  77. for i:=1 to 3 do if mano[i].numero=tot then begin fattoscopa:=true; ricordaid:=i; end;
  78. for i:=1 to 4 do begin h:=1; terna[h]:=tot-table[i].numero; h:=h+1; end;
  79. h:=1;
  80. for i:= 1 to 3 do
  81. begin
  82. som:=0;
  83. for j:=i+1 to 4 do
  84. begin
  85. som:=table[i].numero+table[j].numero;
  86. prendodue[h].somma:=som;
  87. prendodue[h].indice1:=i;
  88. prendodue[h].indice2:=j;
  89. h:=h+1;
  90. end;
  91. end;
  92. if settebinmano=true then
  93. begin for i:=1 to 4 do if table[i].numero=7 then writeln ('7','G',' ','7',table[i].seme); end
  94. else if settebintable=true then
  95. begin for i:=1 to 3 do if mano[i].numero=7 then writeln ('7','G',' ','7',mano[i].seme); end
  96. else if fattoscopa=true then begin write(mano[ricordaid].numero,mano[ricordaid].seme,' ');
  97. for j:=1 to 4 do write(table[j].numero,table[j].seme,' '); writeln;end
  98. else begin for i:=1 to 3 do
  99. if mano[i].numero=7 then for j:=1 to 4 do if table[j].numero=7 then writeln (mano[i].numero, mano[i].seme,' ',table[j].numero, table[j].seme)
  100. else
  101. begin
  102. for h:=1 to 6 do if (prendodue[h].somma=7) then begin trovatosette:=true; ricordaid:=h end;
  103. if trovatosette=true then writeln (mano[i].numero, mano[i].seme,' ',table[prendodue[ricordaid].indice1].numero, table[prendodue[ricordaid].indice1].seme,' ',table[prendodue[ricordaid].indice2].numero, table[prendodue[ricordaid].indice2].seme)
  104. else
  105. begin for w:=1 to 4 do if terna[w]=7 then begin trovatosette:=true; ricordaid:=w; end;
  106. if trovatosette=true then writeln (mano[i].numero, mano[i].seme,' ',table[4-ricordaid+1].numero, table[4-ricordaid+1].seme,' ',table[4-ricordaid+2].numero, table[4-ricordaid+2].seme,' ',table[4-ricordaid+3].numero, table[4-ricordaid+3].seme);
  107. end
  108. end;
  109. end;
  110.  
  111.  
  112. end.
  113.  
Success #stdin #stdout 0.01s 5276KB
stdin
5 G 7 S 3 S
3 G 3 C 1 S 2 C
stdout
7 S 3 S
3 S

3 C 1 S 2 C
1 S 2 C
2 C

7S 2C 6 2
7S 3G 3C
7S 3G 3C
7S 3G 3C