解
2024-08-22 20:14:54
发布于:广东
111阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
using namespace std;
struct Student {
string name;
int id;
int chineseScore;
int mathScore;
};
int main() {
int n, m;
cin >> n >> m;
vector<Student> students(n);
for (int i = 0; i < n; ++i) {
    cin >> students[i].name >> students[i].id >> students[i].chineseScore >> students[i].mathScore;
}
for (int i = 0; i < m; ++i) {
    string queryType;
    cin >> queryType;
    if (queryType == "name") {
        string name;
        cin >> name;
        for (const auto& student : students) {
            if (student.name == name) {
                cout << student.chineseScore << " " << student.mathScore << endl;
                break;
            }
        }
    } else if (queryType == "number") {
        int id;
        cin >> id;
        for (const auto& student : students) {
            if (student.id == id) {
                double average = (student.chineseScore + student.mathScore) / 2.0;
                cout << fixed << setprecision(2) << average << endl;
                break;
            }
        }
    }
}
return 0;
}
这里空空如也


有帮助,赞一个