代码拉取完成,页面将自动刷新
/**
* @file 1080.cpp
* @author Shuang Hu <hsmath@ubuntu>
* @date Sun Apr 11 02:49:35 2021
*
* @brief PAT problem 1080,target:give a program for the master entrance examination
*
*
*/
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class Students{
private:
int entrance_score;
int interview_score;
double final_score;
int rank;
int ID;
public:
int zhiyuan[6];
Students(){
}
void setinfo(int numofchoice,int ID);
double getfinal(){
return final_score;
}
int getentrance(){
return entrance_score;
}
void setrank(int rank){
this->rank=rank;
}
int getrank(){
return rank;
}
int getID(){
return ID;
}
};
void Students::setinfo(int numofchoice,int ID){
cin>>entrance_score>>interview_score;
final_score=(entrance_score+interview_score)*1.0/2;
this->ID=ID;
for(int i=0;i<numofchoice;i++){
cin>>zhiyuan[i];
}
}
class Colleges{
private:
int capacity;
int now;
vector<int> studentID;
public:
Colleges(){
now=0;
}
void setinfo(int capacity){
this->capacity=capacity;
}
int getcapacity(){
return capacity;
}
void luqu(int ID){
studentID.push_back(ID);
now++;
}
bool isfull(){
if(now>=capacity){
return true;
}else{
return false;
}
}
void print(){
if(now>0){
sort(studentID.begin(),studentID.end());
cout<<studentID[0];
for(int i=1;i<studentID.size();i++){
cout<<" "<<studentID[i];
}
}
}
};
bool cmp1(Students& S1,Students& S2){//sort by decreasing sequence
if(S1.getfinal()<S2.getfinal()){
return false;
}else if(S1.getentrance()<S2.getentrance()){
return false;
}else{
return true;
}
}
bool cmp2(Students& S1,Students& S2){//same or not!
if(S1.getfinal()==S2.getfinal()&&S1.getentrance()==S2.getentrance()){
return true;
}
return false;
}
int main(){
int stunum,collegenum,choice;
cin>>stunum>>collegenum>>choice;
vector<Students> StudentDB;
vector<Colleges> CollegeDB;
vector<int> ifcandidate;
for(int i=0;i<collegenum;i++){
Colleges C;
int capacity;
cin>>capacity;
C.setinfo(capacity);
CollegeDB.push_back(C);
ifcandidate.push_back(1);
}
for(int i=0;i<stunum;i++){
Students S;
S.setinfo(choice,i);
StudentDB.push_back(S);
}
sort(StudentDB.begin(),StudentDB.end(),cmp1);
StudentDB[0].setrank(0);
for(int i=1;i<StudentDB.size();i++){
StudentDB[i].setrank(i);
if(cmp2(StudentDB[i],StudentDB[i-1])){
StudentDB[i].setrank(StudentDB[i-1].getrank());
}
}
for(int i=0;i<StudentDB.size();i++){
static int rank=0;
static int nowrank=0;
nowrank=StudentDB[i].getrank();
if(nowrank==rank){
for(int j=0;j<choice;j++){
if(ifcandidate[StudentDB[i].zhiyuan[j]]){
CollegeDB[StudentDB[i].zhiyuan[j]].luqu(StudentDB[i].getID());
break;
}
}
}else{
rank=nowrank;
for(int j=0;j<CollegeDB.size();j++){
if(CollegeDB[j].isfull()){//FULL or NOT
ifcandidate[j]=0;
}
}
for(int j=0;j<choice;j++){
if(ifcandidate[StudentDB[i].zhiyuan[j]]){
CollegeDB[StudentDB[i].zhiyuan[j]].luqu(StudentDB[i].getID());
break;
}
}
}
}
for(int i=0;i<CollegeDB.size();i++){
CollegeDB[i].print();
cout<<endl;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。