1137 Final Grading (25分)

#include<cstdio>
#include<string>
#include<iostream>
#include<vector>
#include <algorithm>//fill()在里面 
#include <cmath>
#include<queue>
#include<unordered_set>
#include<set> 
#include<map>
#include <cstdlib>//貌似是free,malloc等函数的头文件 
using namespace std;

//A1137 编程作业>=200分且最终成绩G必须>=60(100分制)
//计算最后成绩公式: if Gmid>Gfinal :G=(Gmid*0.4+Gfinal*0.6) else G=Gfinal 
//编程分数,期中分数和期末分数分别是三个成绩单,要计算一个同学的得处理三个成绩 
const int INF=1e9; //fill(map[0],map[0]+maxn*maxn,INF); 
const int maxn=10010;

struct node{
	string sid;
	int pro,mid,final,gsum;//还有最后分数最好也存一下,方便排序 
}stu;

vector<node> v,ans;//分别存放第一波和最后筛选出来的学生的名单 
map<string,int> mp;//map存储string到int的映射,这样后面方便后面重复数据的赋值 

int Grade(node student){
	int mid=student.mid;
	int final=student.final;
	double result=0;
	if(mid>final){
		result=mid*0.4+final*0.6;
	}else{
		result=final;
	}
	//如果要在这里给该学生赋值gsum的话,传入的参数得是指针? 
	//round up to:四舍五入取整 :(int)(a+0.5) 
	return (int)(result+0.5);
} 
	//结果按最后分数G降序输出 :如果分数相同(tie平局):按学号升序排列 
bool cmp(node a,node b){//不需要传指针 
	 if(a.gsum==b.gsum)return a.sid<b.sid;//学号按升序
	 return a.gsum>b.gsum;//总分按降序排序 
}
int main(){
	int p,m,n;// <10000
	cin>>p>>m>>n;
	//pro的分数[0,900] mid,final[0,100] 
	//输出能获得证书的学号以及三个成绩
	//输入的时候可以直接筛选掉pro<200的人 
	//期中考试可以不来考,G用Gfinal来计算,如果mid没有输出时用-1代替

	int index=0;//map的下标 
	map<string,int>::iterator it;
	//输入编程成绩 
	while(p--){
		//string只能用cin
		cin>>stu.sid>>stu.pro;
		//stu的期中考试需要初始化,因为期中考试不参加也有可能获得证书
		stu.mid=-1; 
		if(stu.pro>=200){
			v.push_back(stu);
			mp[stu.sid]=index;//对照该学生在v中的位置 
			index++;
		} 
	}
	//输入期中成绩 
	while(m--){
		cin>>stu.sid>>stu.mid;
		//在map里面找sid对应的下标,如果找不到,就不用计算其值
		//map<string, int>中的 int 的初始值是 0,所以在0的位置不存储数据那么就可以把0当做找不到返回的值了
		it=mp.find(stu.sid);
		int pos=-1;//存储索引的下标 
		if(it!=mp.end()){//如果能找到 
			pos=mp[stu.sid];
			v[pos].mid=stu.mid;
		}	
	}
	//输入期末成绩
	while(n--){
		cin>>stu.sid>>stu.final;
		//先找下标
		it=mp.find(stu.sid);
		if(it!=mp.end()){//如果能找到 
			int pos=mp[stu.sid];
			v[pos].final=stu.final;
			//计算最终成绩
			int gsum=Grade(v[pos]);
			if(gsum>=60){
				v[pos].gsum=gsum;
				ans.push_back(v[pos]); 
			}
		}
	} 
	sort(ans.begin(),ans.end(),cmp);
	for(int i=0;i<ans.size();i++){
		cout<<ans[i].sid<<" "<<ans[i].pro<<" "<<ans[i].mid<<" "<<ans[i].final<<" "<<ans[i].gsum<<endl;
	}
	return 0; 
} 

 

请逐句解释一下下面的代码import java.util.Arrays; import org.apache.http.client.fluent.Request; import ece448.iot_sim.SimConfig; import ece448.iot_sim.Main; public class GradeP2 { public static void main(String[] args) throws Exception { SimConfig config = new SimConfig( 8080, Arrays.asList("xxxx", "yyyy", "zzzz.789"), null, null, null); try (Main m = new Main(config)) { Grading.run(new GradeP2(), 10); } } private String get(String pathParams) throws Exception { return Request.Get("http://127.0.0.1:8080"+pathParams) .userAgent("Mozilla/5.0") .connectTimeout(1000) .socketTimeout(1000) .execute().returnContent().asString(); } public boolean testCase00() throws Exception { String ret = get("/xxxx"); return (ret.indexOf("xxxx is off") != -1) && (ret.indexOf("xxxx is on") == -1) && (ret.indexOf("Power reading is 0.000") != -1); } public boolean testCase01() throws Exception { String ret = get("/xxxx?action=on"); return (ret.indexOf("xxxx is on") != -1) && (ret.indexOf("xxxx is off") == -1); } public boolean testCase02() throws Exception { String ret = get("/xxxx?action=off"); return (ret.indexOf("xxxx is off") != -1) && (ret.indexOf("xxxx is on") == -1); } public boolean testCase03() throws Exception { String ret = get("/xxxx?action=on"); return (ret.indexOf("xxxx is on") != -1) && (ret.indexOf("xxxx is off") == -1); } public boolean testCase04() throws Exception { String ret = get("/xxxx?action=toggle"); return (ret.indexOf("xxxx is off") != -1) && (ret.indexOf("xxxx is on") == -1); } public boolean testCase05() throws Exception { String ret = get("/xxxx?action=toggle"); return (ret.indexOf("xxxx is on") != -1) && (ret.indexOf("xxxx is off") == -1); } public boolean testCase06() throws Exception { String ret = get("/yyyy"); return (ret.indexOf("yyyy is off") != -1) && (ret.indexOf("yyyy is on") == -1); } public boolean testCase07() throws Exception { String ret = get("/xxxx"); return (ret.indexOf("xxxx is on") != -1) && (ret.indexOf("xxxx is off") == -1); } public boolean testCase08() throws Exception { String ret = get("/zzzz.789"); return (ret.indexOf("Power reading is 0.000") != -1); } public boolean testCase09() throws Exception { get("/zzzz.789?action=on"); Thread.sleep(1500); String ret = get("/zzzz.789"); return (ret.indexOf("Power reading is 789.000") != -1); } } private static final Logger logger = LoggerFactory.getLogger(HTTPCommands.class); }
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值