Bestcoder_Round#27_1001-Jump and jump...(HDUOJ_5162)

Problem Description

There are n kids and they want to know who can jump the farthest. For each kid, he can jump three times and the distance he jumps is maximum distance amount all the three jump. For example, if the distance of each jump is (10, 30, 20), then the farthest distance he can jump is 30. Given the distance for each jump of the kids, you should find the rank of each kid.

Input

There are multiple test cases. The first line of input contains an integer T (1T100) , indicating the number of test cases. For each test case: The first line contains an integer n (2n3) , indicating the number of kids. For the next n lines, each line contains three integers ai,bi and ci ( 1ai,bi,ci,300 ), indicating the distance for each jump of the i -th kid. It's guaranteed that the final rank of each kid won't be the same (ie. the farthest distance each kid can jump won't be the same).

Output

For each test case, you should output a single line contain n integers, separated by one space. The i -th integer indicating the rank of i -th kid.

Sample Input

   
   
   
   
2 3 10 10 10 10 20 30 10 10 20 2 3 4 1 1 2 1

Sample Output

   
   
   
   
3 1 2 1 2
Hint
For the first case, the farthest distance each kid can jump is 10, 30 and 20. So the rank is 3, 1, 2.
 

比赛的时候一看是排序,唰唰唰敲上一个结构体然后排序然后输出= =比赛结束之后看了题解才发现n最大只到3.。。。。。有种想扁死自己的冲动。这就是一个简单的排序题,没什么好讲的了吧。。。QAQ。

代码

//这是原来的代码QAQ
#include <iostream>

using namespace std;

struct node
{
    int m;
    int n;
    int o;
}no[110],temp;

int main()
{
    ios::sync_with_stdio(false);
    int t,n,a,b,c,i,j;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>a>>b>>c;
            no[i].m=max(max(a,b),c);
            no[i].n=i;
        }
        for(i=0;i<n-1;i++)
        {
            for(j=0;j<n-i-1;j++)
            {
                if(no[j].m<no[j+1].m)
                {
                    temp=no[j];
                    no[j]=no[j+1];
                    no[j+1]=temp;
                }
            }
        }
        for(i=0;i<n;i++)
        {
            no[no[i].n].o=i;
        }
        for(i=0;i<n;i++)
        {
            cout<<no[i].o+1;
            if(i==n-1) cout<<endl;
            else cout<<' ';
        }
    }
    return 0;
}

//这是刚写的
#include <iostream>

using namespace std;

void sort(int a[],int n);

int main()
{
    ios::sync_with_stdio(false);
    int t,n,a,b,c,i,every_max[3];
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>a>>b>>c;
            every_max[i]=max(max(a,b),c);
        }
        sort(every_max,n);
    }
    return 0;
}

void sort(int a[],int n)
{
    int b[3]={1,1,1};
    int i,j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(a[i]<a[j])
            b[i]++;
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<b[i];
        if(i==n-1) cout<<endl;
        else cout<<' ';
    }
}


你可能感兴趣的:(Bestcoder_Round#27_1001-Jump and jump...(HDUOJ_5162))