首页 > 其他 > 详细

A 1137 Final Grading (25分)

时间:2020-06-17 22:10:16      阅读:64      评论:0      收藏:0      [点我收藏+]

一、技术总结

  1. 这一题主要是学会了使用v.push_back(node{id, score, -1, -1, 0})这种方式的赋值插入。
  2. 同时,也知道如果四舍五入向上取整,应该在int型,最后加上0.5。
  3. 还有对于string类型的输出,如果想使用printf进行输出,可以使用函数c_str()

二、参考代码

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
struct node{
	string s;
	int gp, gm, gf, g;
};
bool cmp(node a, node b){
	if(a.g != b.g) return a.g > b.g;
	else return a.s < b.s;
}
map<string, int> idx;
int main(){
	int p, m, n, all_p = 1;
	vector<node> v, ans;
	cin >> p >> m >> n;
	string id;
	int score;
	for(int i = 0; i < p; i++){
		cin >> id >> score;
		if(score >= 200){
			idx[id] = all_p++;
			v.push_back(node{id, score, -1, -1, 0});
		}
	}
	for(int i = 0; i < m; i++){
		cin >> id >> score;
		if(idx[id] != 0) v[idx[id] - 1].gm = score;
	}
	for(int i = 0; i < n; i++){
		cin >> id >> score;
		if(idx[id] != 0){
			int temp = idx[id] - 1;
			v[temp].g = v[temp].gf = score;
			if(v[temp].gf < v[temp].gm) 
				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].s.c_str(), ans[i].gp, ans[i].gm, ans[i].gf, ans[i].g);
	}
	return 0;
}

A 1137 Final Grading (25分)

原文:https://www.cnblogs.com/tsruixi/p/13154788.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!