View Code of Problem 11

#include<iostream>
#include<string.h>
using namespace std;
int main(){
	int t;
	int k=1;
	while(cin>>t&&t!=0){
		int flagk=0;
		getchar();
		while(t--){
			int x1=0,x2=0,y1=0,y2=0,z1=0,z2=0;
			char x='X',y='Y',z='Z';
			char str[10000];
			//getline(cin,str);
			//getchar();
			gets(str);
			int len=strlen(str);
			int flag1=0,flag2=0,flag3=0;
			for(int i=0;i<len;i++){
				if(str[i]-x==0){
					x1=x1+str[i-2]-'0';
					if(flag1==0){
						x2=x2+str[i+2]-'0';
						flag1=1;
					}
					
				}
				else if(str[i]-y==0){
					y1=y1+str[i-2]-'0';
					if(flag2==0){
						y2=y2+str[i+2]-'0';
						flag2=1;
					}
				
				}
				else if(str[i]-z==0){
					z1=z1+str[i-2]-'0';
					if(flag3==0){
						z2=z2+str[i+2]-'0';
						flag3=1;
					}
					
				}
			}
			
			int num[6]={x1,x2,y1,y2,z1,z2};
			
			for(int i=0;i<6;i=i+2){
				if(num[i+1]!=0){
					num[i]=num[i]*num[i+1];
					num[i+1]--;
				}
				else{
					num[i+1]--;
				}

			}
			if(flagk==0){
				printf("Case #%d:\n",k);
				flagk=1;
				k++;
			}
			
			for(int i=0;i<6;i=i+2){
				if(num[i]!=0){
					if(num[i+1]!=-1){
						printf("%d * %c ^ %d",num[i],x+i/2,num[i+1]);
					}
					else{
						printf("%d",num[i]);
					}
					
					
				}
				if(i<4&&i>0){
					if(num[i+2]!=0){
						cout<<" "<<"+"<<" ";
					}
				}
				//if(num[i+2]!=0&&i<4&&i>0)cout<<" "<<"+"<<" ";
			
			}
			cout<<'\n';
			

		}
	}
}

Double click to view unformatted code.


Back to problem 11