PAT甲级 1029median 参考柳神解题思路

先扔完整代码,可通过在线测试,具体迟点再写

#include
#include
using namespace std;
int main()
{
	int m, n;
	cin >> m;
	vector arr1(m);
	for (int i = 0; i < m; i++)
	{
		cin >> arr1[i];
	}
	cin >> n;
	int total = (m + n + 1) / 2;
	int count = 0;
	int i = 0;
	for (int j = 0; j < n; j++)
	{
		int temp = 0;
		cin >> temp;
		while (i < m&&arr1[i] < temp)
		{
			count++;
			if (count == total)
			{
				cout << arr1[i];
			}
			i++;
		}
		count++;
		if (count == total)
		{
			cout << temp;
		}
	}
	while (i < m&&count

想研究的可以先去看柳神的解答

柳神网站:https://www.liuchuo.net/archives/2248

你可能感兴趣的:(pat)