View Code of Problem 10

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int main() {
	int N, a[4];
	scanf("%d", &N);
	while (N--)
	{
		for (int i = 0; i < 4; i++)
			scanf("%d", &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[i];
					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++)
		{
			printf("%d", a[i]);
			if (i < 3)
				printf(" ");
		}
		printf("\n");
	}

}

Double click to view unformatted code.


Back to problem 10