PAT A1062
1308 ワード
簡単な並べ替え問題を含んで、主にcmpとsortの組み合わせの使用に注意します;これまでcmpの戻り条件がよく分からなかったので、ここでまとめます.cmpカスタム関数は、本題の判定と同様に、複数の組み合わせで判定することができる.
上図に示すように、return戻り値のみに注意してください.実は大きくてあまり堅苦しい背中trueやfalseの意味を使わないで、比較要素の関係を見るだけです;昇順シーケンスを望む場合は、aの値がbの値より小さいだけで、降順シーケンスは同じである.詳細コードは次のとおりです.
上図に示すように、return戻り値のみに注意してください.実は大きくてあまり堅苦しい背中trueやfalseの意味を使わないで、比較要素の関係を見るだけです;昇順シーケンスを望む場合は、aの値がbの値より小さいだけで、降順シーケンスは同じである.詳細コードは次のとおりです.
#include
#include
#include
#include
#include
#include
using namespace std;
using std::vector;
struct student{
char id[10];
int de,cai,sum;
int flag;
}stu[100010];
bool cmp(student a,student b){
if(a.flag!=b.flag){
return a.flagb.sum;
}else if(a.de!=b.de){
return a.de>b.de;
}else{
return strcmp(a.id,b.id)<0;
}
}
int N,L,H;
int main(){
scanf("%d%d%d",&N,&L,&H);
int number,t,v;
int m=N;
for(int i=0;i=H&&stu[i].cai>=H)
stu[i].flag=1;
else if(stu[i].de>=H&&stu[i].cai=stu[i].cai)
stu[i].flag=3;
else
stu[i].flag=4;
}
sort(stu,stu+N,cmp);
printf("%d
",m);
for(int i=0;i