A. Array

Source: Internet
Author: User
Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

Vitaly has an arrayNDistinct 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 (cost <limit 0 ).
  2. The product of all numbers in the second set is greater than zero (Priority> limit 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 integerN(3 cores ≤ CoresNLimit ≤ limit 100 ).
The second line containsNSpace-separated distinct integersA1, bytes,A2, middle..., middle ,...,AN(|AI| Limit ≤ limit 103 )-
The array elements.

Output

In the first line print integerN1 (N1 rows> limit 0 )-
The number of elements in the first set. Then printN1 Numbers
-The elements that got to the first set.

In the next line print integerN2 (N2 rows> limit 0 )-
The number of elements in the second set. Then printN2 numbers
-The elements that got to the second set.

In the next line print integerN3 (N3 rows> limit 0 )-
The number of elements in the third set. Then printN3 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 test (s) Input
3-1 2 0
Output
1 -11 21 0
Input
4-1 -2 -3 0
Output
1 -12 -3 -21 0

Description: The requirement for this question is to group the number of columns. The product of the numbers to the first group must be smaller than 0, the product of the second group must be greater than 0, and the product of the third group must be zero. sort the array first, put the smallest number in the first group, and then judge whether there are any numbers greater than 0 in the array, put the smallest number greater than 0 in the second group, and put all the other numbers in the third group. [there must be a 0 in the question.] If there is no number greater than 0, put the two negative numbers in the second group [the product is greater than 0], and the other numbers in the third group.

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>using namespace std;int main() {int i,n,a[100],k;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&a[i]);}sort(a,a+n);cout<<1<<" "<<a[0]<<endl;k=0;for(i=0;i<n;i++){if(a[i]>0) {cout<<1<<" "<<a[i]<<endl;k=a[i];break;}}if(k>0) {cout<<n-2<<" ";for(i=1;i<n;i++){if(a[i]!=k) {cout<<a[i]<<" ";}}}else{cout<<2<<" "<<a[1]<<" "<<a[2]<<endl<<n-3<<" ";for(i=3;i<n;i++){cout<<a[i]<<" ";}}return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.