View Code of Problem 10

#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n,a[4];
	cin>>n;
	while(n--)
	{	
	for(int i=0;i<4;i++)
		cin>>a[i];  
	    for(int i=3;i>0;i--){
		for(int j=i-1;j>=0;j--)
	 	{
	    		if(a[i]==a[j])
	    		{
	    			a[i]=2*a[j];
	    			a[j]=0;
		}}}
	    	
		for(int i=3;i>0;i--)
		{
			if(a[i]==0)
			{
				for(int j=i-1;j>=0;j--)
				{
					if(a[j]>0)
					{
						a[i]=a[j];
						a[j]=0;
						i--;
	

	}}}}
	for(int i=0;i<4;i++)
	{
		if(i==3)
			cout<<a[i]<<endl;
		else
			cout<<a[i]<<" "; 
 		} 

	}
	return 0 ;
}

Double click to view unformatted code.


Back to problem 10