PAT B Brush Road 1080 MOOC title of the final score (25 points)

analysis:

1, because the owner must be programmed G> = 200 min, the array containing all v G with programming> = 200 people, (gm beginning and gf are -1), the name of a map corresponding to map stored in v subscript (in order to avoid "absence" confusion, save index +1, in the case of the student's name 0 indicates absence in v)
2, G names appearing period, if no corresponding map exists ( == 0), indicating that the student program performance condition is not met, there is no need to save the student information. The presence of human midterm exams update
3, G name appears in the end, it must ensure that there is in the map, the end of the first update G and G always new achievements, ending when G <G G period then the total update is (G interim period x 40% + G 60% X)
. 4, the array containing all v G into the overall array meet the conditions ans, ans sort of (decreasing out, out of the same name incremented), the final output ans of student information -
from Liu Chuo

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
struct node {
    string name;
    int gp, gm, gf, g;
};
bool cmp(node a, node b) {
    return a.g != b.g ? a.g > b.g : a.name < b.name;
}
map<string, int> idx;
int main() {
    int p, m, n, score, cnt = 1;
    cin >> p >> m >> n;
    vector<node> v, ans;
    string s;
    for (int i = 0; i < p; i++) {
        cin >> s >> score;
        if (score >= 200) {
            v.push_back(node{s, score, -1, -1, 0});
            idx[s] = cnt++;
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> s >> score;
        if (idx[s] != 0) v[idx[s] - 1].gm = score;
    }
    for (int i = 0; i < n; i++) {
        cin >> s >> score;
        if (idx[s] != 0) {
            int temp = idx[s] - 1;
            v[temp].gf = v[temp].g = score;
            if (v[temp].gm > v[temp].gf) v[temp].g = int(v[temp].gm * 0.4 + v[temp].gf * 0.6 + 0.5);
        }
    }
    for (int i = 0; i < v.size(); i++)
        if (v[i].g >= 60) ans.push_back(v[i]);
    sort(ans.begin(), ans.end(), cmp);
    for (int i = 0; i < ans.size(); i++)
        printf("%s %d %d %d %d\n", ans[i].name.c_str(), ans[i].gp, ans[i].gm, ans[i].gf, ans[i].g);
    return 0;
}

Here is my own doing, it makes all the exam score is 0 points also becomes -1, can not pass the final test point

#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;

struct node{//能拿合格证的学生的信息 
	string Code;
	int gp,gm,gf,g;
};
bool cmp(node a,node b)
{
	if(a.g!=b.g){
		return a.g>b.g;
	}else{
		return a.Code<b.Code;
	}
}
int main()
{
	int P,M,N;
	cin>>P>>M>>N;
	map<string,int> Gp,Gmid,Gfinal;
	int i,j,k,grade;
	string code;//学号
	set<string> tmp;//存所有出现过的名字 
	for(i=0;i<P;i++){
		cin>>code>>grade;
		Gp[code]=grade;
		tmp.insert(code); 
	}
	for(i=0;i<M;i++){
		cin>>code>>grade;
		Gmid[code]=grade;
		tmp.insert(code);
	}
	for(i=0;i<N;i++){
		cin>>code>>grade;
		Gfinal[code]=grade;
		tmp.insert(code);
	}
	map<string,int> G;//总分 
	vector<node> pass;
	for(set<string>::iterator it=tmp.begin();it!=tmp.end();it++){
		if(Gp[*it]>=200){
			if(Gmid[*it]>Gfinal[*it]){
				G[*it]=round((double)Gmid[*it]*0.4+(double)Gfinal[*it]*0.6);
			}else{
				G[*it]=Gfinal[*it];
			}
			if(G[*it]>=60){
				if(Gmid[*it]==0){
					Gmid[*it]=-1;
				} 
				pass.push_back({*it,Gp[*it],Gmid[*it],Gfinal[*it],G[*it]});
			}
		}
	}
	sort(pass.begin(),pass.end(),cmp);
	for(i=0;i<pass.size();i++){
		cout<<pass[i].Code<<" "<<pass[i].gp<<" "<<pass[i].gm<<" "<<pass[i].gf<<" "<<pass[i].g<<endl; 
	}
}
Published 79 original articles · won praise 0 · Views 667

Guess you like

Origin blog.csdn.net/derbi123123/article/details/104036790