#include<stdio.h> #include<string.h> int main() { int n,k=0; while(scanf("%d",&n)!=EOF&&n!=0) { getchar(); printf("Case #%d:\n",++k); for(int i=0;i<n;i++) { char str[2000]; gets(str); int x[2]={0},y[2]={0},z[2]={0}; for(int j=0;j<strlen(str);j++) { if(str[j]=='X') { x[0]+=(str[j-2]-'0'); x[1]=str[j+2]-'0'; } if(str[j]=='Y') { y[0]+=(str[j-2]-'0'); y[1]=str[j+2]-'0'; } if(str[j]=='Z') { z[0]+=(str[j-2]-'0'); z[1]=str[j+2]-'0'; } } if(x[0]!=0&&x[1]!=0) { printf("%d * X ^ %d",x[0]*x[1],x[1]-1); } if(x[1]==0&&x[0]!=0) { printf("%d",x[0]); } if (x[0] != 0 && y[0] != 0)printf(" + "); if(y[0]!=0&&y[1]!=0) { printf("%d * Y ^ %d",y[0]*y[1],y[1]-1); } if(y[1]==0&&y[0]!=0) { printf("%d",y[0]); } if ((z[0] != 0 && y[0] != 0)|| (x[0] != 0 && z[0]!= 0))printf(" + "); if(z[0]!=0&&z[1]!=0) { printf("%d * Z ^ %d",z[0]*z[1],z[1]-1); } if(z[1]==0&&z[0]!=0) { printf("%d",z[0]); } printf("\n"); } } return 0; } |
Double click to view unformatted code.