PAT-B 1041. 考试座位号(15)
2017-02-16 07:34
330 查看
题目链接在此。
这个题目挺直白的,直接看代码好了。
改进方案
这个改进方案是《算法笔记》上的思路,这种改进既节省时间,又节省了空间。
不像上面的代码一样,结构体中有三个变量,而是只有两个(准考证号、座位号),试机座位号作为stu结构体的下标。
这样一来,省去了存储试机座位号的空间,并且不用像上面代码那样遍历stu[]数组去查询,而是直接输出 stu[试机座位号].准考证号、stu[试机座位号].座位号 的对应信息即可。
这个题目挺直白的,直接看代码好了。
#include<stdio.h> struct info{ char stuId[20]; int tryId; int seatId; }stu[1001]; int main(){ int N; scanf("%d",&N); for(int i = 0; i < N; i++){ scanf("%s %d %d",&stu[i].stuId,&stu[i].tryId,&stu[i].seatId); } int M; scanf("%d",&M); for(int i = 0; i < M; i++){ int seatId; scanf("%d",&seatId); for(int j = 0; j < N; j++){ if(stu[j].tryId == seatId){ printf("%s %d\n",stu[j].stuId,stu[j].seatId); break; } } } return 0; }
改进方案
这个改进方案是《算法笔记》上的思路,这种改进既节省时间,又节省了空间。
不像上面的代码一样,结构体中有三个变量,而是只有两个(准考证号、座位号),试机座位号作为stu结构体的下标。
这样一来,省去了存储试机座位号的空间,并且不用像上面代码那样遍历stu[]数组去查询,而是直接输出 stu[试机座位号].准考证号、stu[试机座位号].座位号 的对应信息即可。
相关文章推荐
- [PAT乙级]1041. 考试座位号(15)
- PAT1041考试座位号(15)
- PAT乙级1041. 考试座位号(15)
- PAT(basic level) 1041 考试座位号(15)
- 1041. 考试座位号(15) PAT 乙级
- PAT 乙级 1041. 考试座位号(15) Java版
- PAT 1041. 考试座位号(15)
- PAT Basic 1041. 考试座位号(15)(C语言实现)
- 1041. 考试座位号(15) PAT乙级真题
- PAT 1041. 考试座位号(15)
- 1041. 考试座位号(15) PAT
- PAT训练(乙级)—— 1041. 考试座位号(15)
- PAT-乙级-1041. 考试座位号(15)
- PAT 乙级 1041. 考试座位号(15)
- PAT 1041. 考试座位号(15),两种解法,时间复杂度和空间复杂度对比
- PAT乙级—1041. 考试座位号(15)-native
- PAT 1041. 考试座位号(15)
- 1041. 考试座位号(15)-PAT乙级
- Java - PAT - 1041. 考试座位号(15)
- PAT乙级 1041. 考试座位号(15)