1988.cpp

来自「杭电 acm部分代码 有兴趣的可以下载 谢谢」· C++ 代码 · 共 91 行

CPP
91
字号
#include <iostream>
#include <functional>
using namespace std;
struct num
{
	char fu;
	int k;
};
int store[201];
num bb[51];
int main()
{
	int test, i, j, x, y, n;
	cin >> test;
	for (i = 1; i <= test; i++)
	{
		cin >> n;
		for (j = 1; j <= n; j++)
		{
			cin >> bb[j].fu >> bb[j].k;
		}
		int nums = 0;
		for (j = n; j >= 1; j--)
		{
			if (bb[j].k == j && bb[j].fu == '+')
			{
				continue;	
			}
			if (j == 1)
			{
				store[nums] = 1;
				nums++;
				break;
			}
			for (x = 1; x <= j; x++)
			{
				if (bb[x].k == j)
				{
					break;
				}
			}
			if (x != 1)
			{
				for (y = 1; y <= x; y++)
				{
					bb[y].fu = bb[y].fu == '+' ? '-' : '+';
				}
				for (y = 1; y <= x / 2; y++)
				{
					int a = bb[y].k;
					bb[y].k = bb[x - y + 1].k;
					bb[x - y + 1].k = a;
					char c = bb[y].fu;
					bb[y].fu = bb[x - y + 1].fu;
					bb[x - y + 1].fu = c;		
				}
				store[nums] = x;
				nums++;
			}
			if (bb[1].fu == '+' && bb[1].k == j)
			{
				bb[1].fu = '-';
				store[nums] = 1;
				nums++;
			}
			x = j;
			for (y = 1; y <= x; y++)
			{
				bb[y].fu = bb[y].fu == '+' ? '-' : '+';
			}
			for (y = 1; y <= x / 2; y++)
			{
				int a = bb[y].k;
				bb[y].k = bb[x - y + 1].k;
				bb[x - y + 1].k = a;
				char c = bb[y].fu;
				bb[y].fu = bb[x - y + 1].fu;
				bb[x - y + 1].fu = c;		
			}
			store[nums] = j;
			nums++;
		}
		cout << i << " " << nums;
		for (j = 0; j < nums ; j++)
		{
			cout << " " << store[j];
		}
		cout << endl;
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?