问题描述
根据已输入的准考证号,试机座位号,考试座位号找出指定试机座位号考生的准考证号以及考试座位号。
题目分析
首先我们会顶一个struct结构体student,其中我们只包括准考证号和考试座位号。然后声明一个结构体类型的数组,将输入的试机座位号作为数组的索引,将student对象存入。当我们需要找对应试机座位号的时候,可以直接通过索引访问,然后输出这个student的准考证号和考试座位号。
代码
#include <iostream>
using namespace std;
struct Student{
string str;//准考证号
int test;//考试座位号
};
int main()
{
int number;//学生的人数
cin>>number;
string s;//准考证号
int ss;
int t;
Student student[number + 1];
for(int i = 0;i < number;i++)
{
Student stu;
cin>>s>>ss>>t;
stu.str = s;
stu.test = t;
student[ss] = stu;
}
int search;//要搜索的数
cin>>search;
while(cin>>ss)
{
cout<<student[ss].str<<" "<<student[ss].test<<endl;
if(cin.get() == '\n')
{
break;
}
}
return 0;
}
答题用时7Min
Q41——finish√