View Code of Problem 10

#include<stdio.h>
void main()
{
	int N;
	scanf("%d", &N);
	int a[4];
	int i,j;
	while (N--) {
		scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]);
		for ( i = 3; i > 0; i--)
		{
			int j = i - 1;
			while (a[j] == 0 && j >= 0) {
				j--;
			}
			if (a[i] == a[j]) {
				a[i] += a[j];
				a[j] = 0;
			}
		}
		int b[4] = {0};
		int k = 3;
		for ( i = 3; i >= 0; i--)
		{
			if (a[i] != 0) {
				b[k] = a[i];
				k--;
			}
		}
		for ( i = 0; i < 3; i++)
		{
			printf("%d ", b[i]);
		}
		printf("%d\n", b[3]);
		
	}
}

Double click to view unformatted code.


Back to problem 10