原题链接4.关于去游乐园排队因为人太多于是开始数情侣对数这件事 - 蓝桥云课 (lanqiao.cn)
死活过不去,只能通过一半样例,希望有大佬指导下|?・ω・` )
#include <iostream>
using namespace std;
int main()
{
int num, i;
scanf("%d", &num);
int ans[num];
for (i = 0; i < num; i++)
{
ans[i] = 0;
}
num *= 2;
int nums[num];
for (i = 0; i < num; i++)
{
scanf("%d", &nums[i]);
}
for (int x = 1; x <= num / 2; x++)
{
int j = 0;
for (int y = 0; y < num; y++)
{
for (int v = y + 1; v < num; v++)
{
if (x == nums[y]&& x== nums[v])
{
int teps[num] = { 0 };
int count = 0;
for (i = y; i < v; i++)
{
teps[nums[i] - 1] += 1;
if (teps[nums[i] - 1] == 2)
{
count++;
ans[x-1] = count;
j++;
}
}
}
if (j > 0)
break;
}
if (j > 0)
break;
}
}
for (i = 0; i < num / 2; i++)
{
printf("%d ", ans[i]);
}
return 0;
}