View Code of Problem 11

#include<stdio.h>
#include <string.h>
#include <math.h>
void main()
{
	int i,n,j,k=1,t,q,x[2],y[2],z[2],flag1,flag2,flag3; 
	char a[2000];
 	while(scanf("%d",&n))
	{

		if(n==0)
			break;
		q=n;
		for(i=0;i<n+1;i++)
		{
			gets(a);
			t=strlen(a)-1;
			flag1=0;flag2=0;flag3=0;
			x[0]=0;y[0]=0;z[0]=0;		
			for(j=0;j<t;j++)
			{
				if(a[j]=='X')
				{
					
					flag1=1;
					x[0]=x[0]+(int)(a[j-2]-'0');
					x[1]=(int)(a[j+2]-'0');
				
				}
					if(a[j]=='Y')
				{
					
					flag2=1;
					y[0]=y[0]+(int)(a[j-2]-'0');
					y[1]=(int)(a[j+2]-'0');
					
				}	
					if(a[j]=='Z')
				{
					
						
					flag3=1;
					z[0]=z[0]+(int)(a[j-2]-'0');
					z[1]=(int)(a[j+2]-'0');
					
				}
			}
		
			if(q==n)
			{
				printf("Case #%d:\n",k++);
				q--;
			}
			if(flag1)
			{
				if(flag2==0&&flag3==0)
				{
					if(x[1]!=0)
				printf("%d * X ^ %d\n",x[0]*x[1],x[1]-1);
					else
						printf("%d",x[0]);

				}
				else
				{
					if(x[1]!=0)
				printf("%d * X ^ %d + ",x[0]*x[1],x[1]-1);
					else
						printf("%d + ",x[0]);

				}

			}
			if(flag2)
				{
				if(flag3==0)
				{
					if(y[1]!=0)
				printf("%d * Y ^ %d\n",y[0]*y[1],y[1]-1);
							else
						printf("%d",y[0]);
				}
				else
				{
					if(y[1]!=0)

				printf("%d * Y ^ %d + ",y[0]*y[1],y[1]-1);
					else
						printf("%d + ",y[0]);

				}

			}
			if(flag3)
			{
				if(z[1]!=0)
             printf("%d * Z ^ %d\n",z[0]*z[1],z[1]-1);
				else
					printf("%d\n",z[0]);

			}
			
			 
			}
			
	}
		

    
}

Double click to view unformatted code.


Back to problem 11