View Code of Problem 11

#include<stdio.h>
int a,b,c;
int x1,x2,x3;
int main()
{int time=0;
     int n;
	 int m,z;
	 char w;
	 while(scanf("%d",&n),n!=0)
	 {
	 int i,j;time++;printf("Case #%d:",time);printf("\n");
	 for(i=0;i<n;i++)
	 {
		 a=0;b=0;c=0;x1=0;x2=0;x3=0;
          for(j=0;;j++)
		  {
			  scanf("%d %c %d",&m,&w,&z);
			  if(w=='X') {a+=m;x1=z;}
			  else if(w=='Y') {b+=m;x2=z;}
			  else if(w=='Z') {c+=m;x3=z;}
			  if(getchar()=='\n') break;
		  }
		  if(x1!=0) {a*=x1;x1--;}
		  if(x2!=0) {b*=x2;x2--;}
		  if(x3!=0) {c*=x3;x3--;}
		  if(a!=0)
		  {
		  printf("%d",a);
		  if(x1!=0) printf(" * X ^ %d",x1);
		  if(b!=0||c!=0)printf(" + ");
		  }
		  if(b!=0)
		  {
		  printf("%d",b);
		  if(x2!=0) printf(" * Y ^ %d",x2);
		  if(c!=0) printf(" + ");
		  }
		  if(c!=0)
		  {
		  printf("%d",c);
		  if(x3!=0) printf(" * Z ^ %d",x3);
		  }
		  printf("\n");}
	 }
	 return 0;
}

Double click to view unformatted code.


Back to problem 11