PAT (Basic Level) 1080 MOOC on the final score (analog + stl)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_45458915/article/details/102755133

Topic links: Click here

Subject to the effect: students are given a score of programming, b midterm exam scores of students, c student's final exam results, there are a few rules:

  1. Total rated:
    1. If the result is greater than the midterm exam final exam:G=G_{mid}*0.4+G_{final}*0.6
    2. otherwise:G=G_{final}
  2. Eligible definition programming is not less than 200 and the score after rounding is greater than or equal to 60 Overall
  3. Prioritization are:
    1. Overall Sort press
    2. Student ID then sort

With satisfying the above rules, qualified students descending output information

Topic Analysis: The idea of ​​a simple simulation questions, because this topic will become a student number to string up a difficulty, if it is four or five numbers, then we can directly open structure and store information, but since learning No changes to the string, we have to the structure, with final export maps from map to map the vector convenient ordering, it can directly output the final, the idea is simple, but the implementation a bit messy (refers to code looks chaos), but as stl dependent patients, for a write up is very smooth

There are small details need to pay attention to the topic requires qualified people is greater than or equal after rounding 60 people, which means that a student exam, 59.9 points, is the qualified list of (emmm count? If reality really so nice ah), this small test point 3 corresponds to detail, when we only need to store Overall structure of an int stored on the list, is rounded off in the calculation (int) (a + 0.5), the line

And then there's a small detail, I noticed the problem but do not know that there is no intentional digging that mid-term exam and final exam scored 0 people, originally I was directly trying to gauge whether the mid-term exam scores to judge 0 whether a person to participate in the examination to the expiration, but considering that this detail, it will be the initial value are initialized to -1, so foolproof, there is the program where you can score a little bit cut branches, that is, if the program scores low 200 points in the students will not need a follow-up operation

It is probably the case, directly on the code:

#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
#include<unordered_map>
using namespace std;
 
typedef long long LL;
 
const int inf=0x3f3f3f3f;
 
const int N=1e5+100;

struct Node
{
	int pro;//编程
	int mid;//期中
	int fin;//期末
	int all;//总评
	Node()//初始化为-1
	{
		pro=mid=fin=all=-1;
	}
};

map<string,Node>mp;

bool cmp(pair<string,Node> a,pair<string,Node> b)
{
	if(a.second.all!=b.second.all)//总评降序
		return a.second.all>b.second.all;
	return a.first<b.first;//学号升序
}

int main()
{
//  freopen("input.txt","r",stdin);
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	while(a--)
	{
		string s;
		int num;
		cin>>s>>num;
		if(num<200)//剪枝
			continue;
		mp[s].pro=num;
	}
	while(b--)
	{
		string s;
		int num;
		cin>>s>>num;
		if(mp[s].pro==-1)//剪枝
			continue;
		mp[s].mid=num;
	}
	while(c--)
	{
		string s;
		int num;
		cin>>s>>num;
		if(mp[s].pro==-1)//剪枝
			continue;
		mp[s].fin=num;
	}
	vector<pair<string,Node>>ans;
	copy(mp.begin(),mp.end(),back_inserter(ans));//把map扔到vector里
	for(int i=0;i<ans.size();i++)//按照规则计算总评
	{
		if(ans[i].second.mid>ans[i].second.fin)
			ans[i].second.all=(int)(0.4*ans[i].second.mid+0.6*ans[i].second.fin+0.5);
		else
			ans[i].second.all=ans[i].second.fin;
	}
	sort(ans.begin(),ans.end(),cmp);//按照规则排序
	for(int i=0;i<ans.size();i++)//输出
	{
		if(ans[i].second.all<60)//若当前学生的总评已经不合格了,及时退出
			break;
		printf("%s %d %d %d %d\n",(ans[i].first).c_str(),(ans[i].second).pro,(ans[i].second).mid!=-1?(ans[i].second).mid:-1,(ans[i].second).fin!=-1?(ans[i].second).fin:-1,(ans[i].second).all);
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
   	
   	
   	
   	
     
     
     
     
     
     
     
    return 0;
}

 

Guess you like

Origin blog.csdn.net/qq_45458915/article/details/102755133