zoukankan      html  css  js  c++  java
  • PAT B1041 考试座位号(15)

    解题要点:

    1. 使用结构体保存准考证号,考试座位号
    2. 试机座位号作考生数组下标
    3. 通过试机座位号获取考生号,座位号
    4. 考生号使用long long存放
    //课本AC代码
    #include <cstdio>
    const int maxn = 1010;
    struct Student {
    	long long id;
    	int examSeat;
    } testSeat[maxn];
    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);
    		testSeat[seat].id = id;
    		testSeat[seat].examSeat = examSeat;
    	}
    	scanf("%d", &m);
    	for(int i = 0; i < m; i++) {
    		scanf("%d", &seat);
    		printf("%lld %d
    ", testSeat[seat].id, testSeat[seat].examSeat);
    	}
    	return 0;
    }
    

    自己的WA代码

    #include <cstdio>
    
    const int max_n = 1010;
    
    struct Stu {
    	long long no;	//准考证号
    	int seat_num;
    	int test_num;
    } stu[max_n];
    
    int main() {
    	#ifdef ONLINE_JUDGE
        #else
            freopen("1.txt", "r", stdin);
        #endif // ONLINE_JUDGE
        long long id;
        int seat, examSeat;
    	int testSeat = 0;
    	int n1 = 0, n2 = 0;
    	scanf("%d", &n1);	//输入n个考生信息
    	for(int i = 0; i < n1; i++) {
    		scanf("%lld %d %d", &id, &seat, &examSeat);
    		stu[i].no = id;
    		stu[i].seat_num = seat;
    		stu[i].test_num = examSeat;
    	}
    	scanf("%d", &n2);	//输入n个查询信息
    	/*for(int i = 0; i < n1; i++) {
    		printf("%lld %d %d
     ", stu[i].no, stu[i].seat_num, stu[i].test_num);
    	}
    	for(int i = 0; i < n2; i++) {
    	}*/
    	//误人子弟写法, 复杂度变高了不止, 还wa
    	for(int i = 0; i < n2; i++) {
    		scanf("%d", &testSeat);
    		for(int j = 0; j < n1; j++) {
    			if(testSeat == stu[j].test_num) {
    				printf("%lld %d
    ", stu[i].no, stu[i].test_num);
    			}
    		}
    	}
    
    	return 0;
    }
    
  • 相关阅读:
    C# 删除指定目录下的所有文件及文件夹
    C# 数组集合分页 Skip Take
    MongoDB模糊查询 工具
    C# skip 重试执行代码段
    C# 加载配置文件
    消息队列MSMQ的使用
    C#中const和readonly的区别
    JSP页面中的tab页
    使用jquery获取单选按钮radio的值
    JSP页面获取下来框select选中项的值和文本的方法
  • 原文地址:https://www.cnblogs.com/isChenJY/p/11252047.html
Copyright © 2011-2022 走看看