View Code of Problem 10

#include<iostream>

using namespace std;

int main()
{
    int N;
    cin>>N;
    for(int a=0;a<N;a++)
    {
        int test[4];
        for(int i=0;i<4;i++)
            cin>>test[i];
        for(int i=0;i<4;i++)
        {
            if(test[i]==0)
            {
                for(int j=i;j>0;j--)
                {
                    int temp=test[j];
                    test[j]=test[j-1];
                    test[j-1]=temp;
                }
            }
        }
        for(int i=3;i>0;i--)
        {
            if(test[i]==test[i-1])
            {
                test[i]+=test[i-1];
                for(int j=i-1;j>0;j--)
                {
                    test[j]=test[j-1];
                }
                test[0]=0;
            }
        }
        cout<<test[0]<<" "<<test[1]<<" "<<test[2]<<" "<<test[3]<<endl;
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 10