Sunny News No.5 考试座位号
2018-01-30 18:17
218 查看
题目要求
每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。
输入格式
输入第一行给出一个正整数N(<=1000),随后N行,每行给出一个考生的信息:“准考证号 试机座位号 考试座位号”。其中准考证号由14位数字组成,座位从1到N编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。
考生信息之后,给出一个正整数M(<=N),随后一行中给出M个待查询的试机座位号码,以空格分隔。
输出格式
对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用1个空格分隔。
输入样例
输出样例
设定string型的试机座位号码,可以用顺序存储或链式存储。
顺序存储
#include <iostream>
using namespace std;
struct Node
{
string number;
int computer;
int set;
};
class Student
{
public:
void inputStudent(int n)
{
for(int i = 0 ;i < n ;i++)
{
cin >> a[i].number;
cin >> a[i].computer;
cin >> a[i].set;
}
}
void search(int m, int n)
{
int num;
for (int i = 0; i < m; i++)
{
cin >> num;
for(int j = 0; j < n; j++)
{
if(a[j].computer == num)
{
cout << a[j].number << " " << a[j].set << endl;
break;
}
}
}
return;
}
private:
Node a[100];
};
int main()
{
int n;
cin >> n;
Student s;
s.inputStudent(n);
int m;
cin >> m;
s.search(m, n);
return 0;
}
链式存储
#include <iostream>
using namespace std;
struct Node
{
string number;
int computer;
int set;
Node *next;
};
class Student
{
public:
Student()
{
head = NULL;
}
void inputStudent(int n)
{
Node *p;
Node *q;
for(int i = 0; i < n; i++)
{
p = new Node;
cin >> p->number;
cin >> p->computer;
cin >> p->set;
if(head == NULL)
{
head = p;
q = head;
}
else
{
q->next = p;
q = q->next;
}
}
}
void search(int m, int n)
{
Node *p = head;
int num;
for (int i = 0; i < m; i++)
{
cin >> num;
for(int j = 0; j < n; j++)
{
if(p->computer == num)
{
cout << p->number << " " << p->set << endl;
p = head;
break;
}
p = p->next;
}
}
return;
}
private:
Node *head;
};
int main()
{
int n;
cin >> n;
Student s;
s.inputStudent(n);
int m;
cin >> m;
s.search(m, n);
return 0;
}
2018/1/30
每个PAT考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。
输入格式
输入第一行给出一个正整数N(<=1000),随后N行,每行给出一个考生的信息:“准考证号 试机座位号 考试座位号”。其中准考证号由14位数字组成,座位从1到N编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。
考生信息之后,给出一个正整数M(<=N),随后一行中给出M个待查询的试机座位号码,以空格分隔。
输出格式
对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用1个空格分隔。
输入样例
4 10120150912233 2 4 10120150912119 4 1 10120150912126 1 3 10120150912002 3 2 2 3 4
输出样例
10120150912002 2 10120150912119 1
设定string型的试机座位号码,可以用顺序存储或链式存储。
顺序存储
#include <iostream>
using namespace std;
struct Node
{
string number;
int computer;
int set;
};
class Student
{
public:
void inputStudent(int n)
{
for(int i = 0 ;i < n ;i++)
{
cin >> a[i].number;
cin >> a[i].computer;
cin >> a[i].set;
}
}
void search(int m, int n)
{
int num;
for (int i = 0; i < m; i++)
{
cin >> num;
for(int j = 0; j < n; j++)
{
if(a[j].computer == num)
{
cout << a[j].number << " " << a[j].set << endl;
break;
}
}
}
return;
}
private:
Node a[100];
};
int main()
{
int n;
cin >> n;
Student s;
s.inputStudent(n);
int m;
cin >> m;
s.search(m, n);
return 0;
}
链式存储
#include <iostream>
using namespace std;
struct Node
{
string number;
int computer;
int set;
Node *next;
};
class Student
{
public:
Student()
{
head = NULL;
}
void inputStudent(int n)
{
Node *p;
Node *q;
for(int i = 0; i < n; i++)
{
p = new Node;
cin >> p->number;
cin >> p->computer;
cin >> p->set;
if(head == NULL)
{
head = p;
q = head;
}
else
{
q->next = p;
q = q->next;
}
}
}
void search(int m, int n)
{
Node *p = head;
int num;
for (int i = 0; i < m; i++)
{
cin >> num;
for(int j = 0; j < n; j++)
{
if(p->computer == num)
{
cout << p->number << " " << p->set << endl;
p = head;
break;
}
p = p->next;
}
}
return;
}
private:
Node *head;
};
int main()
{
int n;
cin >> n;
Student s;
s.inputStudent(n);
int m;
cin >> m;
s.search(m, n);
return 0;
}
2018/1/30
相关文章推荐
- 1041. 考试座位号(15) PAT
- L1-005. 考试座位号
- PAT乙级 1041. 考试座位号(15)
- PAT L1-005. 考试座位号
- L1-005. 考试座位号
- [PAT乙级]1041. 考试座位号(15)
- PAT (Basic Level) Practise (中文)1041. 考试座位号(15) C语言
- PAT_考试座位号
- 1041. 考试座位号(15)-PAT乙级真题
- 1041. 考试座位号(15)
- L1-005. 考试座位号
- PAT——1041. 考试座位号(15)
- 1041. 考试座位号(15)
- PAT:考试座位号(C++)
- 1041. 考试座位号(15)
- PAT 1041考试座位号
- PAT乙级 1041.考试座位号(15)
- L1-005 考试座位号
- 浙江大学PAT_乙级_1041. 考试座位号(15)
- PAT-乙级-1041. 考试座位号(15)