PAT (Basic Level) 1041 考试座位号

题意

给定N个学生的学号、试机号和考试号,询问多个试机号对应的学号和考试号。

思路

暴力查就好了。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	vector<tuple<string, int, int>> a(n);
	for (int i = 0; i < n; ++i) {
		string id;
		int x, y;
		cin >> id >> x >> y;
		a[i] = tie(id, x, y);
	}
	int m;
	for (cin >> m; m--;) {
		int x;
		cin >> x;
		for (auto e : a) {
			if (x == get<1>(e)) {
				cout << get<0>(e) << ' ' << get<2>(e) << '\n';
			}
		}
	}
	return 0;
} 

HINT

不定时更新更多题解,Basic Level 全部AC代码,详见 link ! ! !

发布了50 篇原创文章 · 获赞 15 · 访问量 2674

猜你喜欢

转载自blog.csdn.net/abcdefbrhdb/article/details/104593719
今日推荐