PAT-B 1041. 考试座位号(15)
来源:互联网 发布:数据库营销 编辑:程序博客网 时间:2024/05/16 11:57
题目链接在此。
这个题目挺直白的,直接看代码好了。
#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[试机座位号].座位号 的对应信息即可。
0 0
- PAT-B 1041. 考试座位号(15)
- PAT-B 1041. 考试座位号
- PAT-B 1041. 考试座位号
- 【PAT】1041. 考试座位号(15)
- Java - PAT - 1041. 考试座位号(15)
- 1041. 考试座位号(15) PAT 乙级
- PAT乙级.1041. 考试座位号(15)
- PAT 乙级 1041. 考试座位号(15)
- PAT-1041. 考试座位号(15)
- PAT 乙级 1041. 考试座位号(15)
- 1041. 考试座位号(15) PAT
- PAT乙级 1041. 考试座位号(15)
- PAT乙级 1041. 考试座位号(15)
- [PAT乙级]1041. 考试座位号(15)
- PAT乙级1041. 考试座位号(15)
- pat 乙级 1041. 考试座位号(15)
- PAT乙级1041. 考试座位号(15)
- PAT 1041. 考试座位号(15)
- 第23天(就业班) 文件上传及文件下载、邮件发送
- LeetCode258 Add Digits
- named-checkzone命令--Linux命令应用大词典729个命令解读
- smbpasswd命令--Linux命令应用大词典729个命令解读
- Lunix中三个重要时间和find命令
- PAT-B 1041. 考试座位号(15)
- Geoserver2.11矢量切片与OL3中的调用展示
- exit命令--Linux命令应用大词典729个命令解读
- reboot命令--Linux命令应用大词典729个命令解读
- [POJ3155]Hard Life(01分数规划)
- 如何搭建你自己的 Git 服务器呢?
- HADOOP集群搭建_apache官方源码方式搭建
- 向程序发送命令时出现问题 excel
- TensorFlow入门一