📄 1988.cpp
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -