zoukankan      html  css  js  c++  java
  • 【算法笔记】B1041 考试座位号

    1041 考试座位号 (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

    思路:

    需要用试机座位来查询考生,因此可定义一个结构体数组来存放考生的准考证号和考试座位号,试机座位号作为数组下标。

    准考证号使用long long存放。(long long的范围是[ 9*1019 ,9*1019 ])

    CODE:

    #include<iostream>
    #include<string>
    using namespace std;
    struct stu{
        long long id;
        int examSeat;
    }s[1001];
    
    int main(){
        int n, m, seat, examSeat;
        long long id;
        scanf("%d", &n);
        for(int i = 0; i < n; i ++){
            scanf("%lld %d %d", &id, &seat, &examSeat);
            s[seat].id = id;
            s[seat].examSeat = examSeat;
        }
        scanf("%d", &m);
        for(int i = 0; i < m; i ++){
            scanf("%d", &seat);
            printf("%lld %d
    ", s[seat].id, s[seat].examSeat);
        }
        return 0;
    }
  • 相关阅读:
    php中字符与字节的区别
    sql把两值之和当作条件进行查询
    Intel® Neural Compute Stick 2
    使用OpenCV的VideoCapture 读取.mp4文件时出现以下错误:Unable to stop the stream: Inappropriate ioctl for device
    更换Raspbian Buster源
    OpenCV之cv2函数 2
    OpenCV中cv2的用法
    OpenVINO 对象识别 real_time_object_detection Movidius
    树莓派和计算棒实现图形识别 RaspBerry Pi4 with OpenVino and Movidius
    树莓派无线网卡老是掉线
  • 原文地址:https://www.cnblogs.com/chunlinn/p/10528394.html
Copyright © 2011-2022 走看看