1004. 成绩排名 (20)

题目很简单 一次AC 主要是今天做oj用指针又做了一下

#include<bits/stdc++.h>
using namespace std;
struct s{
    string n;
    string x;
    int c;
};
bool cmp(s a,s b)
{
    return a.c>b.c;
}
int main()
{
    int T;
    cin>>T;
    //s p[T];
    //对于我接触的都是定义一个指针指向哪里哪里,比如数组
    //但是这是直接分配一个内存指针来使用
    s *p=new s[T];
    for(int i=0;i<T;i++)
    {
        cin>>p[i].n>>p[i].x>>p[i].c;
    }
    sort(p,p+T,cmp);
    cout<<p[0].n<<" "<<p[0].x<<endl;
    cout<<p[T-1].n<<" "<<p[T-1].x<<endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/wchenchen0/article/details/80009980