基本思路:
一直输出1 -1直到没有1或-1,再连续输出1或-1.
蒟蒻代码
#include <cstdio>
#define m10(x) ((x << 3) + (x << 1))
#define r0 putchar(49), putchar(32)
#define r1 putchar(45), r0
using namespace std;
int n, num[2] = {0, 0};
inline int qread()
{
int ot = 0, t = getchar();
while (t < 48 || t > 57)
t = getchar();
while (t >= 48 && t <= 57)
{
ot = m10(ot) + t ^ 48;
t = getchar();
}
return ot;
}
inline void read()
{
register int f = 0, t = getchar();
while (t != 49)
{
if (t == 45)
f = 1;
t = getchar();
}
++num[f];
return;
}
int main()
{
n = qread();
while (n)
--n, read();
while (num[0] && num[1])
{
--num[0], --num[1];
r0, r1;
}
while (num[0])
--num[0], r0;
while (num[1])
--num[1], r1;
return 0;
}