- 谁拿了最多奖学金
- 2017-04-15 07:12:47 @
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
int n;
class student{
public:
string name;
int sco1,sco2,pap;
char WEST,CAD;
friend void stuqsort(student *a,int l,int r);
friend void namesort(student *a);
void studentn()
{
money=0;
if (WEST=='Y') west=true;
else if (WEST=='N') west=false;
if (CAD=='Y') cad=true;
else if (CAD=='N') cad=false;
if (sco1>80&&pap>0) money+=8000;
if (sco1>85&&sco2>80) money+=4000;
if (sco1>90) money+=2000;
if (sco1>85&&west) money+=1000;
if (sco2>80&&cad) money+=850;
}
int fmoney()
{
return money;
}
private:
bool west,cad;
int money;
};
void namesort(student *a)
{
int i,j,min;
string t;
for(i=0;i<n-1;i++)
{
min=i;//查找最小值
for(j=i+1;j<n;j++)
if(a[min].name>a[j].name)
min=j;//交换
if(min!=i)
{
t=a[min].name;
a[min].name=a[i].name;
a[i].name=t;
}
}
}
void stuqsort(student *a,int l,int r)
{
int i=l,j=r,e=a[(l+r)/2].money;
do{
while (a[i].money>e) i++;
while (a[j].money<e) j--;
if (i<=j)
{
int f=a[i].money;
a[i].money=a[j].money;
a[j].money=f;
string o=a[i].name;
a[i].name=a[j].name;
a[j].name=o;
i++;
j--;
}
}while (i<=j);
if (l<j) stuqsort(a,l,j);
if (i<r) stuqsort(a,i,r);
}
int main()
{
student a[100];
int i;
cin>>n;
for(i=0;i<n;i++){
cin>>a[i].name>>a[i].sco1>>a[i].sco2>>a[i].CAD>>a[i].WEST>>a[i].pap;
a[i].studentn();
}
stuqsort(a,0,n-1);
namesort(a);
cout<<a[0].name<<endl<<a[0].fmoney()<<endl;
int sum=0;
for (i=0;i<n;i++)
sum+=a[i].fmoney();
cout<<sum;
return 0;
}
完美的类操作啊!
2 条评论
-
SW_Wind LV 8 @ 2017-04-18 10:05:46
orz
-
2017-04-15 07:50:53@
???
- 1