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. int string相互转换

    一.itoa()和atoi() 注意:这两个函数并不是标准的C函数,而是windows环境下特有的函数. 1.itoa #include<iostream> #include<str ...

  2. poj 3468 A Simple Problem with Integers (线段树 成段更新 加值 求和)

    题目链接 题意: 只有这两种操作 C a b c" means adding c to each of Aa, Aa+1, ... , Ab. -10000 ≤ c ≤ 10000.&quo ...

  3. POJ 1113 凸包模板题

    上模板. #include <cstdio> #include <cstring> #include <iostream> #include <algorit ...

  4. 函数lock_rec_set_nth_bit

    lock 分配内存 lock = mem_heap_alloc(trx->lock_heap, sizeof(lock_t) + n_bytes); 内存分配图 0xxx 2 xxx 0xxx3 ...

  5. 函数fsp_alloc_from_free_frag

    /**********************************************************************//** Allocates a single free ...

  6. iOS开发:UINavigationController常用操作

    NavigationController常用操作: 更改bar的背景颜色:self.navigationController?.navigationBar.barTintColor =UIColor. ...

  7. BZOJ_1627_[Usaco2007_Dec]_穿越泥地_(bfs)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1627 网格图,给出起点,终点,障碍,求最短路. 分析 简单的宽搜. #include < ...

  8. malloc、free的使用

    一.malloc()和free()的基本概念以及基本用法: 1.函数原型及说明: void *malloc(long NumBytes):该函数分配了NumBytes个字节,并返回了指向这块内存的指针 ...

  9. 【C#学习笔记】List容器使用

    using System; using System.Collections.Generic; namespace ConsoleApplication { class Program { stati ...

  10. Mybatis学习——基本增删改查(CRUD)

    Eclipse+Mybatis+MySql 1.所需jar 2.项目目录 3.源代码 package com.zhengbin.entity; public class Student { priva ...