#include #include int main (void) { int K, k; char occ[51]; char s[31]; int x, y, x1, x2, m; char f; int nd; int t[51]; FILE *in = fopen ("limit.in", "r"); fscanf (in, "%d\n", &K); for (k = 1; k <= K; k ++) { printf ("Data Set %d:\n", k); for (x = 0; x < 51; x ++) occ[x] = -1; nd = 0; x = 0; y = 0; fgets (s, 30, in); s[strlen(s)-1] = 0; while (strcmp (s, "endprogram") != 0) { if (strcmp (s, "basic") == 0) if (y > occ[x]) occ[x] = y; else; else if (strcmp (s, "endloop") == 0) { if (t[nd-1] == 1) x --; else if (t[nd-1] == -1) y --; nd --; } else if (s[5] == 'x') { t[nd] = 1; nd ++; x ++; } else if (s[5] == 'y') { t[nd] = -1; nd ++; y ++; } else { t[nd] = 0; nd ++; } fgets (s, 30, in); s[strlen(s)-1] = 0; } m = -1; for (x = 50; x >= 0; x --) if (occ[x] <= m) occ[x] = -1; else m = occ[x]; for (x1 = 0; x1 < 51; x1 ++) if (occ[x1] >= 0) for (x2 = x1 + 2; x2 < 51; x2 ++) if (occ[x2] >= 0) for (x = x1 + 1; x < x2; x ++) if (((float) occ[x]) <= (float) occ[x1] + ((float)(x-x1)) * ((float)(occ[x2]-occ[x1])) / ((float) (x2-x1))) occ [x] = -1; f = 1; for (x = 50; x >= 0; x --) if (occ[x] >= 0) { if (!f) printf (" + "); f = 0; if (x == 0 && occ[x] == 0) printf ("1"); else { if (x == 1) printf ("x"); else if (x >= 2) printf ("x^%d", x); if (occ[x] == 1) printf ("y"); else if (occ[x] >= 2) printf ("y^%d", occ[x]); } } if (f) printf ("0"); printf ("\n\n"); fscanf (in, "\n"); } fclose (in); return 0; }