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
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

题意:给一组数,要求将其分为三组 每组数乘积分别<0  ==0   >0  输出每组数的个数及这些数(数据满足至少一组解)

题解第一组直接输出一个负数,第二组输出一个正数或两个负数  第三组输出剩余的全部

#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 300
#define mod 100
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int s[MAX],k[MAX];
int main()
{
int n,m,j,i,t,a,b,c;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&s[i]);
int flag=0;
for(i=0;i<n;i++)
{
if(s[i]>0)
{
b=i;
flag=1;
}
}
for(i=0;i<n;i++)
{
if(s[i]<0)
{
c=i;
break;
}
}
j=0;
if(!flag)
for(i=0;i<n;i++)
{
if(i!=c)
{
if(s[i]<0)
k[j++]=s[i];
}
}
printf("1 %d\n",s[c]);
if(flag)
printf("1 %d\n",s[b]);
else
printf("2 %d %d\n",k[0],k[1]);
if(flag)
{
printf("%d ",n-2);
for(i=0;i<n;i++)
{
if(s[i]!=s[c]&&s[i]!=s[b])
printf("%d ",s[i]);
}
printf("\n");
}
else
{
printf("%d ",n-3);
for(i=0;i<n;i++)
{
if(s[i]!=s[c]&&s[i]!=k[0]&&s[i]!=k[1])
printf("%d ",s[i]);
}
printf("\n");
}
}
return 0;
}

  

codeforces300A Array的更多相关文章

  1. javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈

    Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...

  2. ES5对Array增强的9个API

    为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...

  3. JavaScript Array对象

    介绍Js的Array 数组对象. 目录 1. 介绍:介绍 Array 数组对象的说明.定义方式以及属性. 2. 实例方法:介绍 Array 对象的实例方法:concat.every.filter.fo ...

  4. 了解PHP中的Array数组和foreach

    1. 了解数组 PHP 中的数组实际上是一个有序映射.映射是一种把 values 关联到 keys 的类型.详细的解释可参见:PHP.net中的Array数组    . 2.例子:一般的数组 这里,我 ...

  5. 关于面试题 Array.indexof() 方法的实现及思考

    这是我在面试大公司时碰到的一个笔试题,当时自己云里雾里的胡写了一番,回头也曾思考过,最终没实现也就不了了之了. 昨天看到有网友说面试中也碰到过这个问题,我就重新思考了这个问题的实现方法. 对于想进大公 ...

  6. javascript之活灵活现的Array

    前言 就如同标题一样,这篇文章将会灵活的运行Array对象的一些方法来实现看上去较复杂的应用. 大家都知道Array实例有这四个方法:push.pop.shift.unshift.大家也都知道 pus ...

  7. 5.2 Array类型的方法汇总

    所有对象都具有toString(),toLocaleString(),valueOf()方法. 1.数组转化为字符串 toString(),toLocaleString() ,数组调用这些方法,则返回 ...

  8. OpenGL ES: Array Texture初体验

    [TOC] Array Texture这个东西的意思是,一个纹理对象,可以存储不止一张图片信息,就是说是是一个数组,每个元素都是一张图片.这样免了频繁地去切换当前需要bind的纹理,而且可以节省系统资 ...

  9. Merge Sorted Array

    Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:Yo ...

随机推荐

  1. tengine lua 开源一 调用内部接口高效发送文件

    tengine  lua 开源一 调用内部接口高效发送文件 开源自己封装的sendfile 模块,可以高效的通过lua发送文件 源码地址:https://github.com/weinyzhou/Lu ...

  2. Android Studio设置,鼠标放上去有提示

    设置如下: 1. 2. 勾选就可以了

  3. 面试题_93_to_102_编程和代码相关的面试题

    93)怎么检查一个字符串只包含数字?(解决方案) 94)Java 中如何利用泛型写一个 LRU 缓存?(答案<) 95)写一段 Java 程序将 byte 转换为 long?(答案) 95)在不 ...

  4. 最大流算法(Edmons-Karp + Dinic 比较) + Ford-Fulkson 简要证明

    Ford-Fulkson用EK实现:483ms #include <cstdio> #include <cstring> #define min(x,y) (x>y?y: ...

  5. HDU 3746 (KMP求最小循环节) Cyclic Nacklace

    题意: 给出一个字符串,要求在后面添加最少的字符是的新串是循环的,且至少有两个循环节.输出最少需要添加字符的个数. 分析: 假设所给字符串为p[0...l-1],其长度为l 有这样一个结论: 这个串的 ...

  6. [POJ 3498] March of the Penguins

    March of the Penguins Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 4378   Accepted:  ...

  7. textview设置字体的行距和字间距

    字间距 textView有一个属性android:textScaleX是调节字间距的,它的值是一个float型.查看源代码,默认textView 此属性是使用的是: android.internal. ...

  8. excel用vlookup,lookup时查询数据需要排序

    如题,排出来的数据不对,之前没有是看清楚..所以记下来,日是后要小心点....

  9. Linux应用层直接操作GPIO

    Linux应用层直接操作GPIO 在一个老手的指导下,应用层可以直接操作GPIO,具体指设置GPIO的输入输出以及输出电平高或者低.这个大大地提高了灵活性,官方的文档有GPIO Sysfs Inter ...

  10. sql基本语句

    ---恢复内容开始--- 查询有几个不同的职位名称: select distinct name from a: group by: 现在有两个表product和sales,字段分别如下: TABLES ...