Behold, I send you out a|

Rosmontis

园龄:3年6个月粉丝:6关注:3

2022-01-09 18:01阅读: 306评论: 0推荐: 0

PTA团体程序设计天梯赛-练习集 做题笔记 L1-005 考试座位号 (15 分)

PTA团体程序设计天梯赛-练习集 做题笔记

L1-005 考试座位号 (15 分)

每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。

输入格式:

输入第一行给出一个正整数 N(≤1000),随后 N 行,每行给出一个考生的信息:准考证号 试机座位号 考试座位号。其中准考证号由 16 位数字组成,座位从 1 到 N 编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。

考生信息之后,给出一个正整数 M(≤N),随后一行中给出 M 个待查询的试机座位号码,以空格分隔。

输出格式:

对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用 1 个空格分隔。

输入样例:

4
3310120150912233 2 4
3310120150912119 4 1
3310120150912126 1 3
3310120150912002 3 2
2
3 4

输出样例:

3310120150912002 2
3310120150912119 1

以上是题面

题解

做这道题的笔记的原因有两个,第一是锻炼了结构体的使用,刚开始学习算法的同学其实结构体用的比较少,更多的是数组等作为工具;第二是本题有一点哈希查找内味儿,但方便的是题目中他们只能拿着领到的试机座位号码求助于你这句话已经可以看出一点端倪,那就是将本来应有的查找直接变成了常量阶,即将结构体下标直接设定为试机座位号,十分巧妙。原因是每个人的试机座位号、考试座位号、准考证号是唯一且对应的。当我们输入试机座位号进行时,即输入了结构体对应下标,直接访问即可输出准考证号和考试座位号。
以下是代码


/*
 * @Author: 句蒻勾
 * @Date: 2022-01-05 21:28:45
 * @Last Modified by: 句蒻勾
 * @Last Modified time: 2022-01-05 21:13:45
 * @Description: L1-005 考试座位号
*/
#include<bits/stdc++.h>
using namespace std;

struct stuinfo
{
    string number;
    int shi;
    int kao;
}stu[10001];

long long N, M;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    for(int i = 0; i < N; i++){
        string tempn;
        int tempshi = 0;
        int tempkao = 0;
        cin >> tempn >> tempshi >> tempkao;
        stu[tempshi].number = tempn;
        stu[tempshi].shi = tempshi;
        stu[tempshi].kao = tempkao;
    }
    cin >> M;
    while(M--){
        int find = 0;
        cin >> find;
        cout << stu[find].number << " " << stu[find].kao << endl;
    }
    return 0;
}

本文作者:Rosmontis

本文链接:https://www.cnblogs.com/yukight/p/15781697.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Rosmontis  阅读(306)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 春弦 塞壬唱片/横山克
  2. 2 Hold Onto The Light 塞壬唱片
  3. 3 千本樱 初音未来
Hold Onto The Light - 塞壬唱片
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作曲 : David Westbom

Play it cool, let it flow if you don’t wanna know

Play it cool, let it flow if you don’t wanna know

Playing it cool, let it roll, let it go, let it go

Got Thorns out on the front line

And Zima got us on the back line

Play it cool, let it flow, let it flow, let it flow

Yeah

Only Rhodes I know move forward

Only Rhodes I know move forward

Run toward

The monsters in my corner

Strangers

Worse than paranoia

I won’t let you down, I won’t let you down down down

Long nights

Long nights

They don’t pick sides

They don’t pick sides

Offline

We don’t need light

We don’t need light

Real time

Hold onto your light

Hold onto your light

So come on let’s ride

We don’t need light

We don’t need light

Hear the waves

Hear the waves

Hear them crashing on the beach now

It’s getting real, getting real, even as we wait now

And if it wasn’t for Amiya I’d be face down

Yeah, I’d be face down, uh

Medicine for you

When you feel weak

Mysterious soil,

And they all coming back to me

Got no energy to waste

I’m reaching out worlds away

Sharpening up all your blades

Surtr will do the same

Only Rhodes I know move forward

Only Rhodes I know move forward

Run toward

The monsters in my corner

Strangers

Worse than paranoia

I won’t let you down, I won’t let you down down down

Long nights

Long nights

They don’t pick sides

They don’t pick sides

Offline

We don’t need light

We don’t need light

Real time

Hold onto your light

Hold onto your light

So come on let’s ride

We don’t need light

We don’t need light

Stealing the show

Stealing the show

Stealing the show

Stealing the show, nah nah

We are the most

We are the most

We are the most, yeah yeah

Stuck on the coast

Out in the cold

We’re not alone, nah nah

We’re not alone, nah nah

We’re not alone, nah nah

Long nights

Long nights

They don’t pick sides

They don’t pick sides, yeah

Offline

We don’t need light

We don’t need light

Real time

Hold onto your light

Hold onto your light

So come on let’s ride

We don’t need light

We don’t need light

Long nights

Long nights

They don’t pick sides

They don’t pick sides, yeah

Offline

We don’t need light

We don’t need light

Real time

Hold onto your light

Hold onto your light

So come on let’s ride

We don’t need light

We don’t need light

©上海鹰角网络科技有限公司

©上海鹰角网络科技有限公司