题目1069:查找学生信息

来源:互联网 发布:cmd网络测试命令 编辑:程序博客网 时间:2024/05/25 19:56
#include <iostream>#include <fstream>#include <string>using namespace std;const int N = 1010;struct Student{string id;string name;string sex;int age;};Student student[N];int main(){int n, m;#ifndef ONLINE_JUDGEifstream cin("d:\\OJ\\uva_in.txt");#endifwhile (cin >> n) {//cout << "n:" << n << endl;for (int i = 0; i < n; i++) {cin >> student[i].id >> student[i].name >> student[i].sex >> student[i].age;//cout << "name:" << student[i].name << " sex:" << student[i].sex << endl;}cin >> m;string id;for (int i = 0; i < m; i++) {cin >> id;bool found = false;for (int j = 0; j < n; j++) {if (student[j].id == id) {cout << student[j].id << " " << student[j].name << " " << student[j].sex << " " << student[j].age << endl;found = true;break;}}if (!found) cout << "No Answer!" << endl;}}return 0;}

0 0