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.

Sample Input

Input
3
-1 2 0
Output
1 -1
1 2
1 0
Input
4
-1 -2 -3 0
Output
1 -1
2 -3 -2
1 0
题目大意:
给出你一组数据,让你把他分为三类,第一类中数据相乘大于零
第二组数据相乘大于零
第三组数据相乘等于零
所给数据肯定含有零,和负数
并且每一类中一定要含有数据
解题思路
将其分为两类、
1.数据中含有大于零的数
则第一组中放进负数最小值,第二组放进正数最小数
其余放进第三组
2,无大于零的数
第一组放进最大负数
第二组放进两个最大负数
其余放进第三组
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int n,a[10000];
while(~scanf("%d",&n))
{int i,j;for(int i=0;i<n;i++)scanf("%d",&a[i]);sort(a,a+n);if(a[n-1]>0){printf("1 %d\n",a[0]);for(i=1;i<n;i++){if(a[i]>0){printf("1 %d\n",a[i]);break;}}printf("%d",n-2);for(j=1;j<n;j++){if(i!=j)printf(" %d",a[j]);}printf("\n");}else{printf("1 %d\n",a[n-2]);printf("2 %d %d\n",a[n-4],a[n-3]);printf("%d",n-3);for(i=0;i<n-4;i++)printf(" %d",a[i]);printf(" %d\n",a[n-1]);}}
}
												

Codeforces_(A).Array相关推荐

  1. 老男孩上海校区Python面试题

    python面试题 第一章:python基础 数据类型: 1 字典: 1.1 现有字典 dict={'a':24,'g':52,'i':12,'k':33}请按字典中的 value 值进行排序? 1. ...

  2. php recordarray,Array 数组 - [ php中文手册 ] - 在线原生手册 - php中文网

    用户评论: [#1] florenxe [2015-10-07 18:53:45] //a nice little way to print leap years using array for ($ ...

  3. NumPy — 创建全零、全1、空、arange 数组,array 对象类型,astype 转换数据类型,数组和标量以及数组之间的运算,NumPy 数组共享内存

    NumPy 简介 一个用 python 实现的科学计算包.包括: 1.一个强大的 N 维数组对象 Array : 2.比较成熟的(广播)函数库: 3.用于整合 C/C++ 和 Fortran 代码的工 ...

  4. array.array python yhzf

    关于array: Python 本身没有数组这个说法, 有的就是list和tuple, list就具有其他语言中的数组特性. 至于list和tuple的区别,在于list可以在运行时修改内容和大小,t ...

  5. [JS]请给Array本地对象增加一个原型方法,它用于删除数组条目中重复的条目(可能有多个),返回值是一个包含被删除的重复条目的新数组。

    请给Array本地对象增加一个原型方法,它用于删除数组条目中重复的条目(可能有多个),返回值是一个包含被删除的重复条目的新数组. 刚开始复习js题还不太习惯 CSDN上看了一个帖子,说是牛客上的标答, ...

  6. hnswlib RuntimeError: Cannot return the results in a contigious 2D array. Probably ef or M is to sma

    1. 问题现象 index = hnswlib.Index(space = '100', dim = 512) index.init_index(max_elements = 100, ef_cons ...

  7. Array 数组去重 总结10方法(7)

    1,常规双循环去重(缺点:循环次数较多) Array.prototype.unique1 = function(){if(this === null){throw new TypeError('&qu ...

  8. ECMAScript——引用数据类型之array

    array 转载于:https://www.cnblogs.com/cataway/p/4967058.html

  9. leetcode:Search in Rotated Sorted Array

    题目要求: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 ...

  10. intval0.57100 php_php中0,'',null,false,true,FLASE,TREU,array()的相等恒等学习

    //比较值 '' NULL 0 false true FALSE TRUE //相等判断 //'' == NULL == 0 == false (相等) //array() = 0 == NULL = ...

最新文章

  1. 设计模式 之美 -- 简单工厂模式
  2. 面试:5 亿整数的大文件,来排个序?
  3. centos java发送邮件发不出去_传真机发不出传真怎么办 传真机发不出传真解决方法【详解】...
  4. 快速建立自己的个人网站!五款建站程序
  5. Mybatis实体类属性名与数据库类名不对应的两种解决方法
  6. 关于前端设置cookie
  7. 察看网页源代码全攻略
  8. 人工生命 2.0.1 版发布,给青蛙找个工作:走跷跷板
  9. 易语言不用uac权限写到c盘,易语言制作UAC管理员模式添加器
  10. 安装win7和Centos后,默认启动项的修改.
  11. 如何对 Oracle 数据泵(expdp/impdp) 进行 debug
  12. 泡水十几秒仍能工作 小米手机2也能防水了
  13. java线程系列一:Thread类中的start()方法与run方法
  14. GT540M最新驱动(windows XP 32位),安装NDIVIA安装程序无法继续解决方法
  15. 小程序悬浮按钮可拖动自动靠边
  16. java 实现图片的裁剪
  17. PyEcharts 之 仪表盘
  18. 前端构建工具gulpjs的使用介绍及技巧
  19. Java 八种排序算法比较实践
  20. 2021巢湖学院高考成绩查询,2021年巢湖学院录取结果查询网址入口及录取结果公布时间...

热门文章

  1. 老板杜绝员工上班不务正业
  2. 解决SQL server中提示对象名无效
  3. 48 款数据可视化分析工具大集合!
  4. matlab对比度拉伸,[转载][数字图像处理学习]分段线性变换函数——对比度拉伸...
  5. Python练习题答案: 纳特拼音alaphabeta【难度:1级】--景越Python编程实例训练营,1000道上机题等你来挑战
  6. jstl获取表格单元格值_表格单元格和位置绝对值
  7. iOS中百度地图API的总结
  8. 如何让房间每一个角落都充满 Wi-Fi?
  9. css 动画 抖动,css3动画之上下抖动
  10. Jquery不同版本的兼容性