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