Advertisement
Arden

Quest F (December 2012)

Dec 9th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.99 KB | None | 0 0
  1. //F
  2. Var Q1, Q2, Q3:byte;
  3.     N, K, temp1, temp2, i, j:integer;
  4.     input, output:text;
  5.     numbersOfQuestion:array [1..1000] of byte;
  6.     temp:array [1..2,1..14] of byte;
  7. BEGIN
  8. Assign(input,'input.txt');
  9. Assign(output,'output.txt');
  10. Reset(input);
  11. ReadLN(input, Q1, Q2, Q3);
  12. ReadLN(input,N);
  13. temp[1, Q1]:=temp[1, Q1] + 1;
  14. temp[1, Q2]:=temp[1, Q2] + 1;
  15. temp[1, Q3]:=temp[1, Q3] + 1;
  16. for i:= 1 to N do
  17.     Read(input, numbersOfQuestion[i]);
  18. for i:= 1 to N do
  19.     temp[2, numbersOfQuestion[i]]:= temp[2, numbersOfQuestion[i]] + 1;
  20. for i:= 14 downto 1 do
  21. if (temp[1, i] + temp[2, i]) >= 3 then
  22.    Begin
  23.         j:= i;
  24.         break;
  25.    End;
  26. if (j = i) then
  27.    Begin
  28.         while temp[1, j] <> 3 do
  29.         Begin
  30.         for i:= 1 to 14 do
  31.         if (i <> j) then temp[1, i]:= 0;
  32.         temp[2, j]:= temp[2, j] - 1;
  33.         temp[1, j]:= temp[1, j] +1 ;
  34.         K:= K+1;
  35.    End;
  36. Close(input);
  37. Rewrite(output);
  38. WriteLN(output, K);
  39. for i:= 1 to 14 do
  40.     While temp[1, i] <> 0  Do
  41.     Begin
  42.          Write(output, i, ' ');
  43.          temp[1, i]:= temp[1, i]-1;
  44.     End;
  45.     End
  46. else
  47.     Begin
  48.          for i:= 1 to 14 do
  49.              if (temp[1, i] <> 0) then
  50.              Begin
  51.                  temp1:= i;
  52.                  break;
  53.              End;
  54.          for i:= 14 downto 1 do
  55.              if (temp[2,i] <> 0) then begin; temp2:= i;
  56.                 break;
  57.              end;
  58.          temp[1, temp1]:= temp[1, temp1] - 1;
  59.          temp[1, temp2]:= temp[1, temp2] + 1;
  60.          K:= 1;
  61.          Rewrite(output);
  62.          WriteLN(output, K);
  63.          for i:=14 downto 1 do
  64.              if (temp[1,i] <> 0) then
  65.                 Begin
  66.                      Write(output, i, ' ');
  67.                      temp[1, i]:= temp[1, i]-1;
  68.                      break;
  69.                 End;
  70.          for i:= 1 to 14 do
  71.          while temp[1, i] <> 0  do
  72.          Begin
  73.               Write(output, i, ' ');
  74.               temp[1, i]:= temp[1, i] - 1;
  75.          End;
  76.     End;
  77. Close(output);
  78. END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement