首页 > 学院 > 开发设计 > 正文

PAT 1012

2019-11-08 02:00:43
字体:
来源:转载
供稿:网友
#include<cstdio>#include<algorithm>#include<stdlib.h>#include<cstring>using namespace std;struct student{	int id;	int score[4];}st[1000010];char map[4]={'A','C','M','E'};int now;int k[1000010][4]={0};//局部变量是放在栈里面的,栈的空间通常都不会太大,定义这么大一个局部数组,放在main函数内会导致栈溢出。//一般来说,大数组最好不要定义为局部变量,要么改成全局变量,要么使用动态内存分配。 bool cmp(student x,student y){		return x.score[now]>y.score[now];}int main(){		int n,m;		scanf("%d%d",&n,&m);	for(int i=0;i<n;i++)	{		scanf("%d%d%d%d",&st[i].id,&st[i].score[1],&st[i].score[2],&st[i].score[3]);		st[i].score[0]=st[i].score[1]+st[i].score[2]+st[i].score[3];//round	}		for(now=0;now<4;now++)	{		 sort(st,st+n,cmp);		 k[st[0].id][now]=1;		 for(int j=1;j<n;j++)		 {			 if(st[j].score[now]!=st[j-1].score[now])				 k[st[j].id][now]=j+1;			 else 				 k[st[j].id][now]=k[st[j-1].id][now];						 }	}	int query;	for(int i=0;i<m;i++)	{		scanf("%d",&query);		if(k[query][0]==0)			PRintf("N/A/n");		else		{			int x=0;			for(int y=1;y<4;y++)			{				if(k[query][y]<k[query][x])				{					x=y;								}			}			printf("%d %c/n",k[query][x],map[x]);		}	}	system("pause");	return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表