#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { int t, count = 0; while(1) { scanf("%d", &t); count++; if (t == 0) { break; } printf("Case #%d:\n", count); int i = 0; int x, y, z; int a, b, c; a = b = c = 0; x = y = z = 0; getchar(); while (i < t) { char s = getchar(); int temp; if (s == '\n') { i++; if (a != 0) { if (x == 0) { printf("%d", a); } else{ printf("%d * X ^ %d", a * x, x - 1); } } if (b != 0) { if (a != 0) { printf(" + "); } if (y == 0) { printf("%d", b); } else{ printf("%d * Y ^ %d", b * y, y - 1); } } if (c != 0) { if (b != 0) { printf(" + "); } else if(a != 0) { printf(" + "); } if (z == 0) { printf("%d", c); } else{ printf("%d * Z ^ %d", c * z, z - 1); } } a = b = c = 0; x = y = z = 0; printf("\n"); continue; } else if(s >= '0' && s <= '9') { temp = s - '0'; } else if(s == 'X') { a += temp; getchar(); x = getchar() - '0'; } else if(s == 'Y') { b += temp; getchar(); y = getchar() - '0'; } else if(s == 'Z') { c += temp; getchar(); z = getchar() - '0'; } } } } |
Double click to view unformatted code.