Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- FILE *fin;
- char c;
- ///1 if A,2 if B, 0 if not enough
- int winnerGame(int x,int y)
- {
- if (x>=4 && x-y>=2) return 1;
- if (y>=4 && y-x>=2) return 2;
- return 0;
- }
- ///returns 1 if A wins
- ///returns 2 if B wins
- ///returns 0 if incomplete
- int makeGame()
- {
- int pointA = 0;
- int pointB = 0;
- while(!winnerGame(pointA,pointB))
- {
- c = getc(fin);
- if(c == '\n' || c == EOF) break;
- if(c=='A') ++pointA;
- else ++pointB;
- }
- return winnerGame(pointA,pointB);
- }
- ///1 if A,2 if B, 0 if not enough
- int winnerSet(int x,int y)
- {
- if (x>=6 && x-y>=2) return 1;
- if (y>=6 && y-x>=2) return 2;
- return 0;
- }
- ///returns 1 if A wins
- ///returns 2 if B wins
- ///returns 0 if incomplete
- int makeSet()
- {
- int gameA = 0, gameB = 0,x;
- while(!winnerSet(gameA,gameB))
- {
- x = makeGame();
- if(x == 1) ++gameA;
- if(x == 2) ++gameB;
- if(x == 0) break;
- }
- if(winnerSet(gameA,gameB) == 0) printf("Partial ");
- printf("Set score: A-%d B-%d\n",gameA,gameB);
- return winnerSet(gameA,gameB);
- }
- void terminateLine()
- {
- while(c!='\n' && c!=EOF) c = getc(fin);
- }
- ///1 if A,2 if B, 0 if not enough
- int winnerMatch(int x,int y)
- {
- if(x + y < 2) return 0;
- if(x > y) return 1;
- if(y > x) return 2;
- return 0;
- }
- ///returns 1 if A wins
- ///returns 2 if B wins
- ///returns 0 if incomplete
- void makeMatch()
- {
- int setA = 0, setB = 0,x;
- while(!winnerMatch(setA,setB))
- {
- x = makeSet();
- if(x == 1) ++setA;
- if(x == 2) ++setB;
- if(x == 0) break;
- }
- if(winnerMatch(setA,setB) == 0) printf("Match incomplete.\n");
- else if(winnerMatch(setA,setB) == 1) printf("Match over, A wins.\n");
- else printf("Match over, B wins.\n");
- terminateLine();
- }
- int main()
- {
- fin = fopen("date.in","r");
- while(c!=EOF)
- {
- makeMatch();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement