1137 Final Grading

本文介绍了一个学生成绩管理系统的设计与实现,该系统使用C++语言,通过结构体和MAP数据结构存储和处理学生在线课程、期中、期末及总成绩。系统能够根据总分排序并筛选出及格的学生名单。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述在这里插入图片描述

题目大意:

每个学生有四个成绩,线上成绩,期中,期末,总分。现在分别给出这四门成绩下对应的学生分数情况。要求按照总分从大到小(分数相同则按照ID字典序升序)输出总分及格(>=60分)的学生成绩情况。线上成绩必须不小于200分。

解题思路:

用MAP给每名学生分配唯一的编号方便用结构体保存信息并排序,输入时对于线上成绩小于200的学生不保存。
代码如下:

#include<iostream>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
map<string,int> s;//给每个ID编号
int p,g1,g2,inde=1;
struct stu
{
	int online=-1,gt=-1,gf=-1,f;
	char ids[30];
}data[11000];
int cmp(stu a,stu b)
{
	if(a.f==b.f)//总分相同
	{
		return strcmp(a.ids,b.ids)<0;//字典序升序
	}
	else return a.f>b.f;
}
int main()
{
	scanf("%d %d %d",&p,&g1,&g2);
	for(int i=0;i<p;i++)
	{
		char id[30];
		int score;
		scanf("%s %d",id,&score);
		string t=string(id);
		if(score>=200)//线上课小于200的不参与排序
		{
			s[t]=inde;//MAP标记
			data[inde].online=score;
			strcpy(data[inde].ids,id);
			inde++;
		}
	}
	for(int i=0;i<g1;i++)
	{
		char id[30];
		int score;
		scanf("%s %d",id,&score);
		string t=string(id);
		if(s[t]!=0)
		{
			int cur=s[t];
			data[cur].gt=score;
		}
	}
	for(int i=0;i<g2;i++)
	{
		char id[30];
		int score;
		scanf("%s %d",id,&score);
		string t=string(id);
		if(s[t]!=0)
		{
			int cur=s[t];
			data[cur].gf=score;
			if(data[cur].gf>=data[cur].gt)data[cur].f=score;//计算总分
			else
			{
				double tes=data[cur].gt*0.4+score*0.6+0.5;
				data[cur].f=tes;
			}
		}
	}
	sort(data+1,data+inde+1,cmp);//下标是从1开始的
	for(int i=1;i<inde;i++)
	{
		if(data[i].f>=60)
		printf("%s %d %d %d %d\n",data[i].ids,data[i].online,data[i].gt,data[i].gf,data[i].f);
	}
	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、付费专栏及课程。

余额充值