View Code of Problem 11

#include<stdio.h>
#include<string.h> 
int main(){
	int x1=0,xn=0,y1=0,yn=0,z1=0,zn=0;
	int i=0,j=0,t=0,len=0,flag;
	int xs=0,zs=0,count=0;
	char data[1001],f;
	while(scanf("%d",&t)!=EOF){
		if(t!=0)
			printf("Case #%d:\n",++count);
		getchar();
		for(i=0;i<t;i++){
			xs=0;zs=0;x1=0;xn=0;y1=0;yn=0;z1=0;zn=0;len=0;
			gets(data);
			len=strlen(data);
			for(j=0;j<len;){
				xs=data[j]-'0';
				f=data[j+2];
				zs=data[j+4]-'0';
				
				if(f=='X') {
					x1+=xs;
					xn=zs;
				}else if (f=='Y'){
					y1+=xs;
					yn=zs;
				}else if(f=='Z'){
					z1+=xs;
					zn=zs;
				}
				xs=data[j];
				j=j+6;
			} 
			if(x1*xn!=0) printf("%d * X ^ %d",x1*xn,xn-1);
			if(x1!=0&&xn==0) printf("%d",x1);
			if(x1!=0&&y1!=0) printf(" + ");
			if(y1*yn!=0) printf("%d * Y ^ %d",y1*yn,yn-1);
			if(y1!=0&&yn==0) printf("%d",y1);
			if((x1!=0&&z1!=0)||(z1!=0&&y1!=0)) printf(" + ");
			if(z1*zn!=0) printf("%d * Z ^ %d",z1*zn,zn-1);
			if(z1!=0&&zn==0) printf("%d",z1);
			printf("\n");
		}
	}
}

Double click to view unformatted code.


Back to problem 11