View Code of Problem 11

#include<stdio.h>
#include<string.h> 
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF&&n!=0)
	{	
		char str[2000];
		for(int i=0;i<n;i++)
		{
			getchar();
			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';
				}
			}
			x[0]=x[0]*x[1];x[1]--;
			y[0]=y[0]*y[1];y[1]--;
			z[0]=z[0]*z[1];z[1]--;
			printf("Case #%d:\n",i+1);
			if(x[0]!=0&&x[1]!=0)	
			{
				printf("%d * X ^ %d",x[0],x[1]);
			}
			else if(x[1]==0)
			{
				printf("%d",x[0]);
			}
			if(y[0]!=0&&y[1]!=0)	
			{
				printf(" + %d * Y ^ %d",y[0],y[1]);
			}
			else if(y[1]==0)
			{
				printf("%d",y[0]);
			}
			if(z[0]!=0&&z[1]!=0)	
			{
				printf(" + %d * Z ^ %d\n",z[0],z[1]);
			}
			else if(z[1]==0)
			{
				printf("%d\n",z[0]);
			}		
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 11