您的位置:首页 > 其它

浙大PAT甲级 1055

2016-08-23 20:24 411 查看
简单题,首先将输入的信息先后按照worth递减,年龄递增,名字字典序递增来进行排序。

然后对于每个查询,从头开始遍历输出最多M个的年龄在范围内的信息。

AC代码:

#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<list>
#include<set>
#include<stack>
#include<cmath>
#define inf 26*26*26*10+5
using namespace std;
struct node
{
char name[10];
int age;
int data;
};
bool cmp(node x,node y)
{
if(x.data!=y.data)
{
return x.data>y.data;
}
else
{
if(x.age!=y.age)
return x.age<y.age;
else
return strcmp(x.name,y.name)<0;
}
}
vector<node> v;
int main()
{
int n,m;
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++)
{
node tmp;
scanf("%s %d %d",tmp.name,&tmp.age,&tmp.data);
v.push_back(tmp);
}
sort(v.begin(),v.end(),cmp);
for(int i=0;i<m;i++)
{
int d,l,r;
scanf("%d %d %d",&d,&l,&r);
int num=0;
printf("Case #%d:\n",i+1);
int len=v.size();
for(int i=0;i<len;i++)
{
if(v[i].age>=l&&v[i].age<=r&&num<d)
{
printf("%s %d %d\n",v[i].name,v[i].age,v[i].data);
num++;
}
}
if(num==0)
{
printf("None\n");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: