题解
2025-03-23 15:49:32
发布于:江苏
6阅读
0回复
0点赞
了解我的应该知道这个不是我做的,而是Deepseek......
#include<iostream>
#include<map>
#include<string>
#include<iomanip>
using namespace std;
struct Student {
string name;
string number;
int chinese;
int math;
};
int main() {
int n,m;
cin>>n>>m;
map<string, Student> nameMap;
map<string, Student> numberMap;
for (int i = 0; i < n; i++) {
Student stu;
cin>>stu.name>>stu.number>>stu.chinese>>stu.math;
nameMap[stu.name] = stu;
numberMap[stu.number] = stu;
}
for (int i = 0; i < m; i++) {
string type, query;
cin>>type>>query;
if (type == "name") {
Student stu = nameMap[query];
cout << stu.chinese << " " << stu.math << endl;
}
else if(type=="number"){
Student stu = numberMap[query];
double average = (stu.chinese + stu.math) / 2.0;
cout << fixed << setprecision(2) << average << endl;
}
}
}
这里空空如也
有帮助,赞一个