首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【CodeForces】300A - Array(思维)

【CodeForces】300A - Array(思维)

作者头像
FishWang
发布2025-08-26 20:24:44
发布2025-08-26 20:24:44
8500
代码可运行
举报
运行总次数:0
代码可运行

点击打开题目

A. Array

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Vitaly has an array of n distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:

  1. The product of all numbers in the first set is less than zero ( < 0).
  2. The product of all numbers in the second set is greater than zero ( > 0).
  3. The product of all numbers in the third set is equal to zero.
  4. Each number from the initial array must occur in exactly one set.

Help Vitaly. Divide the given array.

Input

The first line of the input contains integer n (3 ≤ n ≤ 100). The second line contains n space-separated distinct integers a1, a2, ..., an(|ai| ≤ 103) — the array elements.

Output

In the first line print integer n1 (n1 > 0) — the number of elements in the first set. Then print n1 numbers — the elements that got to the first set.

In the next line print integer n2 (n2 > 0) — the number of elements in the second set. Then print n2 numbers — the elements that got to the second set.

In the next line print integer n3 (n3 > 0) — the number of elements in the third set. Then print n3 numbers — the elements that got to the third set.

The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.

Examples

input

代码语言:javascript
代码运行次数:0
运行
复制
3
-1 2 0

output

代码语言:javascript
代码运行次数:0
运行
复制
1 -1
1 2
1 0

input

代码语言:javascript
代码运行次数:0
运行
复制
4
-1 -2 -3 0

output

代码语言:javascript
代码运行次数:0
运行
复制
1 -1
2 -3 -2
1 0

题目出的太给面子了,保证了解肯定存在而且可以任意输出一组结果。

保证肯定有负数和0。

既然有负数,首先输出一个负数即可。

然后分个情况,如果有正数,则输出一个正数,其他的和0一起输出;如果没有正数,输出两个负数,其他的和0输出。

注意格式。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
	int num[111];
	int n;
	while (~scanf ("%d",&n))
	{
		for (int i = 1 ; i <= n ; i++)
			scanf ("%d",&num[i]);
		sort (num+1,num+n+1);
		printf ("1 %d\n",num[1]);
		if (num[n] > 0)		//有正数的情况,输出一个正数即可 
		{
			printf ("1 %d\n",num[n]);
			printf ("%d",n-2);
			for (int i = 2 ; i < n ; i++)
				printf (" %d",num[i]);
			printf ("\n");
		}
		else		//没有正数输出两个负数 
		{
			printf ("2 %d %d\n",num[2],num[3]);
			printf ("%d",n-3);
			for (int i = 4 ; i <= n ; i++)
				printf (" %d",num[i]);
			printf ("\n");
		}
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-08-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档