做完后已经🤢🤮🤮🤧😇
2026-01-02 18:35:29
发布于:广东
6阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct Student {
string id;
string name;
string gender;
int age;
};
bool check(const vector<Student>& students,const string& t,int pos){
return students[pos].id >= t;
}
int main(){
int N;
cin >> N;
vector<Student> students(N);
int max_len = 0;
for (int i=0;i<N;i++){
cin >> students[i].id >> students[i].name >> students[i].gender >> students[i].age;
}
int M;
cin >> M;
for (int i=0;i<M;i++){
string Q;
cin >> Q;
int result = -1;
int left = 0;
int right = N-1;
while (left <= right) {
int mid = (left + right) / 2;
if (check(students,Q,mid)) {
result = mid;
right = mid - 1;
} else {
left = mid + 1;
}
}
if (result != -1 && students[result].id == Q) {
cout << students[result].id << " "
<< students[result].name << " "
<< students[result].gender << " "
<< students[result].age << endl;
} else {
cout << "No Answer!" << endl;
}
}
return 0;
}
这里空空如也






有帮助,赞一个