#include<stdio.h> #include<string.h> int main() { int n; int k=0; int x1, x2, y1, y2, z1, z2; while (scanf("%d",&n)!=EOF) { getchar(); if (n == 0) break; printf("Case #%d:\n", ++k); while (n--) { x1=0, x2 = 0, y1 = 0, y2 = 0, z1 = 0, z2 = 0; char ch[2001]; gets(ch); int len = strlen(ch); for (int i = 0; i < len; i++) { if (ch[i] == 'X') { x1 += (ch[i - 2] - '0'); x2 = (ch[i + 2] - '0'); } if (ch[i] == 'Y') { y1 += (ch[i - 2] - '0'); y2 = (ch[i + 2] - '0'); } if (ch[i] == 'Z') { z1 += (ch[i - 2] - '0'); z2 = (ch[i + 2] - '0'); } } if (x2 == 0 && x1 != 0) printf("%d", x1); if (x2 != 0 && x1 != 0) printf("%d * X ^ %d", x1*x2,x2-1); if (x1 != 0 && y1 != 0)printf(" + "); if (y2 == 0 && y1 != 0) printf("%d", y1); if (y2 != 0 && y1 != 0) printf("%d * Y ^ %d", y1*y2, y2 - 1); if ((z1 != 0 && y1 != 0)|| (x1 != 0 && z1 != 0))printf(" + "); if (z2 == 0 && z1 != 0) printf("%d", z1); if (z2 != 0 && z1 != 0) printf("%d * Z ^ %d", z1*z2, z2 - 1); printf("\n"); } } return 0; } |
Double click to view unformatted code.