###### weixin_44047790

2019-08-12 10:15 浏览 361

# 大一c++算法类作业问题

（没有c币，劳烦各位大佬了。）

``````#include "pch.h"
#include <iostream>
#include<string>
using namespace std;

class DC
{
private:
string num;//考号
int D, C;//德才分
bool can;//过不过录取线
int sum;//总分
int lei;//属于哪一类，1（都过H），2（D过HC不过）,3（D>C），4分别代表4类
public:
DC() {
lei = 0;
D = 0;
C = 0;
can = false;
sum = 0;
}
void get(int L, int H) {
cin >> num >> D >> C;
sum = D + C;
if (D >= L && C >= L)
{
can = true;
if (D >= H && C >= H)
{
lei = 1;
}
else if (D >= H && C < H)
{
lei = 2;
}
else if (D > C&&D < H && C < H)
{
lei = 3;
}
else lei = 4;
}
else
{
can = false;
lei = 5;
}
}
void print()
{
cout << num << " " << D << " " << C << endl;
}
bool rcan() { return can; }
int rsum() { return sum; }
int rlei() { return lei; }
string rnum() { return num; }
int rD() { return D; }
};
int main()
{
int N, L, H;
int M = 0;//合格人数
int i, j;
cin >> N >> L >> H;
DC *p = new DC[N];
for (i = 0; i < N; i++)
{
(p + i)->get(L, H);
if ((p + i)->rcan())M++;
}
DC D;
//对总分进行排序
for (i = 0; i < N - 1; i++)
{
for (j = i+1; j < N; j++)
{
if ((p + i)->rlei() > (p + j)->rlei())
{
D = *(p + i);
*(p + i) = *(p + j);
*(p + j) = D;
}
}
}
for (i = 0; i < N - 1; i++)
{
for (j = i+1; j < N ; j++)
{
if ((p + i)->rlei() == (p + j)->rlei() && (p + i)->rsum() < (p + j)->rsum())
{
D = *(p + i);
*(p + i) = *(p + j);
*(p + j) = D;
}
else if ((p + i)->rlei() == (p + j)->rlei() && (p + i)->rsum() == (p + j)->rsum())
{
if ((p + i)->rD() < (p + j)->rD())
{
D = *(p + i);
*(p + i) = *(p + j);
*(p + j) = D;
}
else if ((p + i)->rD() == (p + j)->rD())
{
if ((p + i)->rnum() > (p + j)->rnum())
{
D = *(p + i);
*(p + i) = *(p + j);
*(p + j) = D;
}
}
}
}
}
cout << M << endl;
for (i = 0; i < N; i++)
{
if ((p + i)->rcan())
{
(p + i)->print();
}
}
delete[] p;
}
``````
• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享
• 邀请回答