zoukankan      html  css  js  c++  java
  • Codeforces 300A Array

    题目链接:http://codeforces.com/problemset/problem/300/A

    由于题目保证有解,所以能够把数组排序,最小的数分在第一组。然后最大的数假设大于0就分在第二组。其余的数和0分在第三组(比赛的时候仅仅记得0乘0是0。居然忘记0乘其他数也是0了.....Orz)。

    假设最大的数小于0或等于0。。说明比它小的数一定小于0。把排序后的数组的第二和第三的数放在第二组,一定能保证乘积为正,剩下的和0分为一组。

    #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
    ",a[0]);
            if(a[n-1]>0)
            {
                printf("1 %d
    ",a[n-1]);
                printf("%d %d",n-2,a[n-2]);
                for(i=1; i<n-2; i++)
                    printf(" %d",a[i]);
                printf("
    ");
            }
            else
            {
                printf("2 %d %d
    ",a[1],a[2]);
                printf("%d %d",n-3,a[n-1]);
                for(i=3; i<n-1; i++)
                    printf(" %d",a[i]);
                printf("
    ");
            }
        }
        return 0;
    }
    


  • 相关阅读:
    PAT 甲级 1115 Counting Nodes in a BST (30 分)
    PAT 甲级 1114 Family Property (25 分)
    PAT 甲级 1114 Family Property (25 分)
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
    Python Ethical Hacking
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6855877.html
Copyright © 2011-2022 走看看