http://ac.jobdu.com/problem.php?pid=1069
题目描述:输入N个学生的信息,然后进行查询
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
typedef struct Student
{
string ID;
string name;
string sex;
int age;
}Student;
int main()
{
int n, m, i,j;
string key;
//ifstream cin("data.txt");
while (cin >> n)
{
Student *student = new Student[n];
for (i = 0; i < n; i++)
{
cin >> student[i].ID >> student[i].name >> student[i].sex >> student[i].age;
}
cin >> m;
for (i = 0; i < m; i++)
{
cin >> key;
for (j = 0; j < n; j++)
{
if (student[j].ID == key)
{
cout << student[j].ID << " " << student[j].name << " " << student[j].sex << " " << student[j].age << endl;
break;
}
}
if (j == n)
cout << "No Answer!" << endl;
}
}//end of while
//system("pause");
return 0;
}