Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. FILE *fin;
  5. char c;
  6.  
  7. ///1 if A,2 if B, 0 if not enough
  8. int winnerGame(int x,int y)
  9. {
  10. if (x>=4 && x-y>=2) return 1;
  11. if (y>=4 && y-x>=2) return 2;
  12.  
  13. return 0;
  14. }
  15.  
  16. ///returns 1 if A wins
  17. ///returns 2 if B wins
  18. ///returns 0 if incomplete
  19. int makeGame()
  20. {
  21. int pointA = 0;
  22. int pointB = 0;
  23.  
  24. while(!winnerGame(pointA,pointB))
  25. {
  26. c = getc(fin);
  27. if(c == '\n' || c == EOF) break;
  28.  
  29. if(c=='A') ++pointA;
  30. else ++pointB;
  31. }
  32.  
  33. return winnerGame(pointA,pointB);
  34. }
  35.  
  36. ///1 if A,2 if B, 0 if not enough
  37. int winnerSet(int x,int y)
  38. {
  39. if (x>=6 && x-y>=2) return 1;
  40. if (y>=6 && y-x>=2) return 2;
  41.  
  42. return 0;
  43. }
  44.  
  45.  
  46. ///returns 1 if A wins
  47. ///returns 2 if B wins
  48. ///returns 0 if incomplete
  49. int makeSet()
  50. {
  51. int gameA = 0, gameB = 0,x;
  52.  
  53. while(!winnerSet(gameA,gameB))
  54. {
  55. x = makeGame();
  56. if(x == 1) ++gameA;
  57. if(x == 2) ++gameB;
  58. if(x == 0) break;
  59. }
  60.  
  61. if(winnerSet(gameA,gameB) == 0) printf("Partial ");
  62.  
  63. printf("Set score: A-%d B-%d\n",gameA,gameB);
  64.  
  65. return winnerSet(gameA,gameB);
  66. }
  67.  
  68. void terminateLine()
  69. {
  70.  
  71. while(c!='\n' && c!=EOF) c = getc(fin);
  72. }
  73.  
  74.  
  75. ///1 if A,2 if B, 0 if not enough
  76. int winnerMatch(int x,int y)
  77. {
  78. if(x + y < 2) return 0;
  79. if(x > y) return 1;
  80. if(y > x) return 2;
  81.  
  82. return 0;
  83. }
  84.  
  85.  
  86. ///returns 1 if A wins
  87. ///returns 2 if B wins
  88. ///returns 0 if incomplete
  89. void makeMatch()
  90. {
  91. int setA = 0, setB = 0,x;
  92.  
  93. while(!winnerMatch(setA,setB))
  94. {
  95. x = makeSet();
  96. if(x == 1) ++setA;
  97. if(x == 2) ++setB;
  98. if(x == 0) break;
  99. }
  100.  
  101. if(winnerMatch(setA,setB) == 0) printf("Match incomplete.\n");
  102. else if(winnerMatch(setA,setB) == 1) printf("Match over, A wins.\n");
  103. else printf("Match over, B wins.\n");
  104.  
  105. terminateLine();
  106. }
  107. int main()
  108. {
  109. fin = fopen("date.in","r");
  110.  
  111. while(c!=EOF)
  112. {
  113. makeMatch();
  114. }
  115. return 0;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement