当前位置:网站首页>P1051 who won the most Scholarships (simple sort)

P1051 who won the most Scholarships (simple sort)

2021-08-10 08:04:11 wx6110fa547fd20

P1051 Who got the most Scholarships ( Simple order )

  Subject portal

The question : Name and scholarship of the student seeking the most bonus , And the total number of scholarships for everyone .

Ideas : Just sort the structure .

#include<bits/stdc++.h>
using namespace std;
struct p{
	string s;
	int a,b;
	char c,d;
	int e,id,sum;
}f[105];
bool cmp(p x,p y){
	return x.sum==y.sum?x.id<y.id:x.sum>y.sum; 
}
int main(){
	int n,tot=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>f[i].s>>f[i].a>>f[i].b>>f[i].c>>f[i].d>>f[i].e,f[i].sum=0,f[i].id=i;
	if(f[i].a>80&&f[i].e>0) f[i].sum+=8e3;
	if(f[i].a>85&&f[i].b>80) f[i].sum+=4e3;
	if(f[i].a>90) f[i].sum+=2e3;
	if(f[i].a>85&&f[i].d=='Y') f[i].sum+=1e3;
	if(f[i].b>80&&f[i].c=='Y') f[i].sum+=850; 
	tot+=f[i].sum;
	}
	sort(f+1,f+n+1,cmp);
	cout<<f[1].s<<endl;
	printf("%d\n%d\n",f[1].sum,tot);
	return 0;
}

      
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.

版权声明
本文为[wx6110fa547fd20]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/08/20210810080205545P.html

随机推荐