题解 | #查找学生信息#
查找学生信息
https://www.nowcoder.com/practice/fe8bff0750c8448081759f3ee0d86bb4
#include<iostream>
#include<string>
#include<algorithm>
#include<string>
using namespace std;
struct info {
string id, name, sex, age;
bool flag;
info() {
flag = false;
}
info(int a, int b, int c, int d) {
id = a, name = b, sex = c, age = d, flag = true;
}
} stu_info[1001];
int str2int() {
return 0;
}
int main() {
int N;
cin >> N;
while (N--) {
string id, name, sex, age;
cin >> id >> name >> sex >> age;
int index = stoi(id);
stu_info[index].id = id, stu_info[index].name = name, stu_info[index].sex = sex,
stu_info[index].age = age;
stu_info[index].flag = true;
}
int M;
cin >> M;
while (M--) {
string query;
cin >> query;
int query_index = stoi(query);
info temp = stu_info[query_index];
if (temp.flag == true) {
cout << temp.id << " " << temp.name << " " << temp.sex << " " << temp.age <<
endl;
} else {
cout << "No Answer!" << endl;
}
}
}
查看11道真题和解析