View Code of Problem 11

#include <iostream>
using namespace std;

int main(){
	int n;cin>>n;
	int x[10]={0};
	int y[10]={0};
	int z[10]={0};
	int cont=0;
	while(n--){
		char a[2000]={0};
		int i=0;
		int q=1;
		while(q!=0){	
			cin>>a[i];i++;
			if(a[i-1]=='0')q=0;			
			}

		for(int j=0;j<i;j++){
			if(a[j]=='X'){
				int t=a[j+1]-'0';
				int m=a[j-1]-'0';
				x[t-1]+=t*m;
			}
			if(a[j]=='Y'){
				int t=a[j+1]-'0';
				int m=a[j-1]-'0';
				y[t-1]+=t*m;
			}
			if(a[j]=='Z'){
				int t=a[j+1]-'0';
				int m=a[j-1]-'0';
				z[t-1]+=t*m;
			}
		}
			cont++;
			cout<<"Case #"<<cont<<":"<<endl;
			int  M=0,N=0;
			for(int i=0;i<10;i++){
				if(x[i]!=0){
					cout<<x[i]<<" * X ^ "<<i;
					x[i]=0; M=1;break;
				}	
			} 
			if(M==1){
			 
			for(int i=0;i<10;i++){
				if(x[i]!=0){
					cout<<" + "<<x[i]<<" * X^ "<<i;
				}
			} 
			for(int i=0;i<10;i++){
				if(y[i]!=0){
					cout<<" + "<<y[i]<<" * Y^ "<<i;
				}
			} 
			for(int i=0;i<10;i++){
				if(z[i]!=0){
					cout<<" + "<<z[i]<<" * Z^ "<<i;
				}
			} 
		}
		else {		
			for(int i=0;i<10;i++){
				if(y[i]!=0){
					cout<<y[i]<<" * Y ^ "<<i;
					y[i]=0; N=1;break;
				}	
			}
			if(N==1){ 
			for(int i=0;i<10;i++){
				if(y[i]!=0){
					cout<<" + "<<y[i]<<" * Y^ "<<i;
				}
			} 
			for(int i=0;i<10;i++){
				if(z[i]!=0){
					cout<<" + "<<z[i]<<" * Z^ "<<i;
					}
				} 
			}
			else{
					for(int i=0;i<10;i++){
					if(y[i]!=0){
						cout<<z[i]<<" * Z ^ "<<i;
						z[i]=0; break;
					}	
				}
				for(int i=0;i<10;i++){
					if(z[i]!=0){
					cout<<" + "<<z[i]<<" * Z^ "<<i;
					}
				} 
			}
		}
	}
	return 0;
}
/*
Main.c:1:20: fatal error: iostream: No such file or directory
 #include <iostream>
                    ^
compilation terminated.
*/

Double click to view unformatted code.


Back to problem 11