1 Star 0 Fork 0

hsmath/PAT advanced

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
1025.cpp 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
hsmath 提交于 2021-07-25 00:11 . 1025
/**
* @file 1025.cpp
* @author Shuang Hu <hsmath@ubuntu>
* @date Sat Jul 24 23:52:49 2021
*
* @brief PAT advanced 1025
*
*
*/
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
class student{
public:
int score;
string ID;
int grouprank;
int allrank;
int groupID;
};
bool cmp(student& s1,student& s2){
if(s1.score>s2.score){
return true;
}else if(s1.score==s2.score){
if(s1.ID<s2.ID){
return true;
}
}
return false;
}
class exam{
private:
vector<student> candidates;
int groupnum;
int stunum;
public:
exam();
void solve();
void print();
};
exam::exam(){
cin>>groupnum;
stunum=0;
for(int i=1;i<=groupnum;i++){
vector<student> mygroup;
int stus=0;
cin>>stus;
stunum+=stus;
for(int j=0;j<stus;j++){
student stu;
cin>>stu.ID>>stu.score;
stu.groupID=i;
mygroup.push_back(stu);
}
sort(mygroup.begin(),mygroup.end(),cmp);
for(int j=0;j<stus;j++){
mygroup[j].grouprank=j+1;
if(j!=0){
if(mygroup[j].score==mygroup[j-1].score){
mygroup[j].grouprank=mygroup[j-1].grouprank;
}
}
candidates.push_back(mygroup[j]);
}
}
}
void exam::solve(){
sort(candidates.begin(),candidates.end(),cmp);
for(int i=0;i<candidates.size();i++){
candidates[i].allrank=i+1;
if(i!=0){
if(candidates[i].score==candidates[i-1].score){
candidates[i].allrank=candidates[i-1].allrank;
}
}
}
}
void exam::print(){
cout<<stunum<<endl;
for(int i=0;i<candidates.size();i++){
cout<<candidates[i].ID<<" "<<candidates[i].allrank<<" "<<candidates[i].groupID<<" "<<candidates[i].grouprank<<endl;
}
}
int main(){
exam Ex;
Ex.solve();
Ex.print();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/hsmath/pat-advanced.git
git@gitee.com:hsmath/pat-advanced.git
hsmath
pat-advanced
PAT advanced
master

搜索帮助