Problem K: 结构体数组的定义初始化

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:14 Solved:10

Description

定义一个学生结构体,数据成员包括学号、姓名、年龄,输入学生的人数及相应学生的信息,输出第k个学生的信息。

Input

第1行:输入学生的人数n(1<=n<=10)
第2行到第n+1行:输入每个学生的学号、姓名、年龄

Output

每一行输出一个学生的数据,学号、姓名、年龄用1个空格分隔

Sample Input Copy

3
1001011 wangli 12
1001012 lijun 11
1001013 zaobin 12

Sample Output Copy

1001011 wangli 12
1001012 lijun 11
1001013 zaobin 12

HINT

结构体使用的方法:
#include<bits/stdc++.h> //包含万能头文件 
using namespace std; //使用标准命名空间 
struct student{
int xh; //定义学号为整数类型 
string xm; //定义1个字符串类型表示姓名 
int nl; //定义1个整型表示年龄 
};  //构造一个结构体类型,类型名叫:student 
student a[11]; //定义一个数组a,每个元素是student类型 
int n;
int main() //主函数,返回值的数据类型是整型 
{
cin>>n;
for(int i=0;i<n;i++) //对结构体中成员赋值
{
cin>>a[i].xh;
cin>>a[i].xm;
cin>>a[i].nl;
}
for(int i=0;i<n;i++) //输出每个学生的信息 
  cout<<a[i].xh<<' '<<a[i].xm<<' '<<a[i].nl<<endl;
return 0; //返回0 
}

Source/Category