Codeforces 300A Array

Source: Internet
Author: User

Title Link: Http://codeforces.com/problemset/problem/300/A

Because the problem is guaranteed to have a solution, so you can sort the array, the smallest number in the first group, and then the largest number if it is greater than 0 in the second group, the remaining number and 0 points in the third group (when the game only remember 0 times 0 is 0, unexpectedly forget 0 by the other number is 0). ORZ). If the maximum number is less than 0 or equal to 0, indicating that the number smaller than it must be less than 0, the second and third number of the sorted array is placed in the second group, it is guaranteed that the product is positive, the remaining and 0 are grouped together.

 #include <cstdio> #include <iostream> #include <sstream> #include < cstdlib> #include <cstring> #include <string> #include <climits> #include <cmath> #include <algorithm> #include <queue> #include <vector> #include <stack> #include <set> #include    <map>using namespace Std;int main () {int n,a[105];        while (~SCANF ("%d", &n)) {int i;        for (i=0; i<n; i++) scanf ("%d", &a[i]);        Sort (a,a+n);        printf ("1%d\n", a[0]);            if (a[n-1]>0) {printf ("1%d\n", a[n-1]);            printf ("%d%d", n-2,a[n-2]);            for (I=1; i<n-2; i++) printf ("%d", a[i]);        printf ("\ n");            } else {printf ("2%d%d\n", a[1],a[2]);            printf ("%d%d", n-3,a[n-1]);            for (i=3; i<n-1; i++) printf ("%d", a[i]);        printf ("\ n"); }} return 0;} 


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 300A Array

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.