#include int serve, justserved; int score[2]; int n[2]; int lasttouch, numbertouch; void lose (int team) { if (serve != team) score[1-team] ++; serve = 1-team; lasttouch = 0; numbertouch = 0; } int teamof (int player) { if (player <= n[0]) return 0; else return 1; } int main (void) { int k, K, t, i; int p, ws; char s[3001]; char *c; FILE *in = fopen ("ball.in", "r"); fscanf (in, "%d\n", &K); for (k = 1; k <= K; k ++) { fscanf (in, "%d %d %d\n", &n[0], &n[1], &t); fgets (s, 3001, in); s[strlen(s)-1] = 0; score[0] = score[1] = 0; lasttouch = 0; numbertouch = 0; serve = -1; ws = 0; for (i = 1; i <= t; i ++) { if (i == 1) c = strtok (s, " \n"); else c = strtok (NULL, " \n"); switch (c[0]) { case 'A': lose (0); break; case 'B': lose (1); break; case 'X': lose (teamof(lasttouch)); break; default: sscanf (c, "%d\n", &p); if (numbertouch == 0) if ((1-teamof(p)) == serve) ws = 1; else {serve = teamof(p); lasttouch = p; justserved = 1; numbertouch = 1;} else if (lasttouch == p) lose (teamof(p)); else if (teamof(lasttouch) == teamof(p)) { numbertouch ++; if ((numbertouch > 3) || justserved) lose (teamof(p)); else lasttouch = p; } else { numbertouch = 1; justserved = 0; lasttouch = p; } } } printf ("Data Set %d:\n", k); if (ws) printf ("Wrong Serve\n"); else printf ("%d %d\n", score[0], score[1]); } fclose (in); return 0; }