hdu 1236 排名(排序)

考察排序,比較水的一題,加強一下對符號的重載,內用了stl處理,所以程序就變的相對簡單了~~


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <vector>
using namespace std;
struct stu
{
    string s;
    int score;
    bool operator > (const stu m)const
    {
        if(score==m.score)return m.s > s;
        return score > m.score;
    }
};

stu st[1005];
vector<stu>ans;
int exam[15];
int n;

void init()
{
    int i;
    for(i=0; i<n; i++)st[i].score=0;
    ans.clear();
}

int main()
{

    while (~scanf("%d",&n)&&n)
    {
        init();
        int m,g;
        scanf("%d%d",&m,&g);
        int i;
        for(i=1; i<=m; i++)scanf("%d",&exam[i]);
        for(i=0; i<n; i++)
        {
            cin>>st[i].s;
            int tm;
            scanf("%d",&tm);
            while(tm--)
            {
                int temp;
                scanf("%d",&temp);
                st[i].score+=exam[temp];
            }
            if(st[i].score>=g)ans.push_back(st[i]);
        }
        sort( ans.begin(),ans.end(),greater<stu>() );
        printf("%d\n",ans.size());
        for(i=0; i<ans.size(); i++)
        {
            cout<<ans[i].s<<" ";
            printf("%d\n",ans[i].score);
        }
    }
    return 0;
}










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