经过分析,此题目使用结构体数组较为简单,由于属性中涉及到姓名、性别的存储,所以使用c++中字符串类型比较方便。
代码如下:
#include<iostream>
using namespace std;
typedef struct student{
int id;
string sname;
string sex;
int age;
}stu;
stu s[20];
int main()
{
int m;
cin>>m;
while(m--)
{
int n;
cin>>n;
int i;
for(i=0;i<n;i++)//向顺序表中输入数据
cin>>s[i].id>>s[i].sname>>s[i].sex>>s[i].age;
int index;
cin>>index;
int t=index-1;
cout<<s[t].id<<" "<<s[t].sname<<" "<<s[t].sex<<" "<<s[t].age;
cout<<"\n";
}
return 0;
}
注意:c语言中没有string类型----存储字符串。若想使用c语言存储字符串,需要使用数组,比较麻烦。