考试座位号 (15分)
总结:
1.涉及N个数据,都为整型:
- ①行或列为N-1 的二维数组:一个做下标,N-1个存储在数组内。
(如a/b/c,用str[a][2]来存储,b=str[a][0],c=str[a][1])
- ②结构体数组:一个下标,N-1个作为结构体内的数据存储。
2.三个数据都唯一且一一对应,都可做下标。最好将试机号作为下标。(输入试机号,就可以直接给出结果)
3.16位数字,在long long范围内(18位)。
代码:
#include <cstdio>
struct Student{
long long test; //准考证
int seat; //考试座位
};
int main(){
int n,m;
scanf("%d", &n);
Student stu[n+1];//定义结构体数组Student stu[n+1] 试机座位号作为下标
long long t1; int p1; int s1;
for(int i=0; i<n; i++){
scanf("%lld%d%d",&t1, &p1, &s1);
stu[p1].seat = s1;
stu[p1].test = t1;
}
scanf("%d", &m);
int temp;
for(int i=0; i<m; i++){
if(i != 0 ) printf("\n");
scanf("%d", &temp);
printf("%lld %d", stu[temp].test, stu[temp].seat );
}
return 0;
}