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