#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> int main(){//这是什么鬼题目 int t,k=0; char str[2000]; while(scanf("%d",&t)!=EOF&&t!=0){ getchar(); k++; printf("Case #%d:\n",k); while(t--){ int x[2]={0,-1},y[2]={0,-1},z[2]={0,-1}; scanf("%[^\n]",str); getchar(); for(int i=0;i<strlen(str);i++){ switch(str[i]){ case 'X': x[0]+=str[i-2]-'0'; if(str[i+2]=='0'){ str[i+2]='1'; } x[1]=str[i+2]-'0'; break; case 'Y': y[0]+=str[i-2]-'0'; if(str[i+2]=='0'){ str[i+2]='1'; } y[1]=str[i+2]-'0'; break; case 'Z': z[0]+=str[i-2]-'0'; if(str[i+2]=='0'){ str[i+2]='1'; } z[1]=str[i+2]-'0'; break; default:break; } } x[0]*=x[1]; x[1]-=1; y[0]*=y[1]; y[1]-=1; z[0]*=z[1]; z[1]-=1; int flag1=0,flag2=0; if(x[1]>=0&&y[1]>=0&&x[0]!=0&&y[0]!=0){ flag1=1; }else if(x[1]>=0&&z[1]>=0&&x[0]!=0&&z[0]!=0){ flag1=1; } if(y[1]>=0&&z[1]>=0&&y[0]!=0&&z[0]!=0){ flag2=1; } if(x[1]>0&&x[0]!=0){ printf("%d * X ^ %d",x[0],x[1]); }else if(x[1]==0&&x[0]!=0){ printf("%d",x[0]); } if(flag1==1){ printf(" + "); } if(y[1]>0&&y[0]!=0){ printf("%d * Y ^ %d",y[0],y[1]); }else if(y[1]==0&&y[0]!=0){ printf("%d",y[0]); } if(flag2==1){ printf(" + "); } if(z[1]>0&&z[0]!=0){ printf("%d * Z ^ %d\n",z[0],z[1]); }else if(z[1]==0&&z[0]!=0){ printf("%d\n",z[0]); }else{ printf("\n"); } } } return 0; } |
Double click to view unformatted code.