LCR 177. 撞色搭配

LCR 177. 撞色搭配_第1张图片

LCR 177. 撞色搭配

LCR 177. 撞色搭配
LCR 177. 撞色搭配_第2张图片

迷你游戏之寻找两个单身狗

int* sockCollocation(int* sockets, int socketsSize, int* returnSize)
{
	int* arr = (int*)malloc(2 * sizeof(int));

	int ret = 0;
	for (int i = 0; i < socketsSize; i++)
	{
		ret ^= sockets[i];
	}

	int pos = 0;
	for (int i = 0; i < 32; i++)
	{
		if (ret & (1 << i))
		{
			pos = i;
			break;
		}
	}

	int m = 0;
	for (int i = 0; i < socketsSize; i++)
	{
		if (sockets[i] & (1 << pos))
		{
			m ^= sockets[i];
		}
	}
	int n = ret ^ m;

	arr[0] = m;
	arr[1] = n;

	*returnSize = 2;

	return arr;
}

你可能感兴趣的:(C家家精品好题,C语言经典题目,c++,数据结构,c语言)