題目811 變態最大值

已AC代碼:

 
#include<cstdio>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    while((scanf("%d", &n)) != EOF)
    {
        int a[n], b[3], t=1, j=0;
        while(n)
        {
            for(int i=0; i<3; i++)
            {
                scanf("%d", &b[i]);
                n--;
                if(i==2)
                {
                    sort(b, b+3);
                    if(t%2==1)
                        a[j]=b[2];
                    else
                        a[j]=b[0];
                    j++;
                    t++;
                }
                else if(n==0)
                {
                    sort(b, b+n%3);
                    if(t%2==1)
                        a[j]=b[n%3-1];
                    else
                        a[j]=b[0];
                    j++;
                }
            }
        }
        sort(a, a+j);
        printf("%d\n", a[j-1]);

    }
}
        


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章