A Qualifiers Ranking Rules---The 2023 ICPC Asia Regionals Online Contest (1)

The following is the current ranking rules for the ICPC Asia EC Online Qualifiers, and there will be two online contests.

  1. In each contest, only the rank of the top-ranked team from each university will be taken as the score of that university;
  2. In each contest, participating universities will be ranked according to their scores;
  3. The two rankings of universities are combined using the merge sorting method. For any two universities that obtain the same ranking in different contests, the university that received this ranking in the first contest will be ranked first.
  4. Delete duplicate universities and obtain the final ranking of all participating universities (only the highest rankings for each university are retained).

Now assuming that there are n teams in the first contest and m teams in the second contest.

For each contest, given the ranking of each team and the university to which it belongs, please output the final ranking of all participating universities according to the above rules.

You can better understand this process through the sample.

Input

The first line contains two integers n,m (1≤n,m≤1e4) , representing the number of teams participating in the first contest and the second contest.

Then following n lines, the i-th line contains a string si​ (1≤∣si​∣≤10) only consisting of uppercase letters, representing the abbreviation of the university to which the i-th ranked team in the first contest belongs.

Then following m lines, the i-th line contains a string ti​ (1≤∣ti​∣≤10) only consisting of uppercase letters, representing the abbreviation of the university to which the i-th ranked team in the second contest belongs.

It's guaranteed that each university has only one abbreviation.

Output

Output several lines, the i-th line contains a string, representing the abbreviation of the i-th ranked university in the final ranking.

You should ensure that the abbreviation of any participating universities appears exactly once.

Input Sample

14 10
THU
THU
THU
THU
XDU
THU
ZJU
THU
ZJU
THU
NJU
WHU
THU
HEU
PKU
THU
PKU
PKU
ZJU
NUPT
THU
NJU
CSU
ZJU

Output Sample

THU
PKU
XDU
ZJU
NJU
NUPT
WHU
HEU
CSU

Hint

Sample is part of the results in 2022 ICPC Asia EC Online Contest.

In the first contest, the ranking of the universities is:

THU
XDU
ZJU
NJU
WHU
HEU

In the second contest, the ranking of the universities is:

PKU
THU
ZJU
NUPT
NJU
CSU

By combining these two rankings according to the rules, the rankings of the universities is:

THU
PKU
XDU
THU
ZJU
ZJU
NJU
NUPT
WHU
NJU
HEU
CSU

By deleting duplicate universities we will get the final ranking.

解析:

首先对于两个榜单,统计并且去重。

然后对于榜单a和b进行遍历,并且记录是否重复。

注意,有的学校可能没参加某一场,所以可能导致两场榜单去重之后长度不一样。

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,m;
string s;
vector<string>a,b,res;
set<string>p;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		cin>>s;
		if(p.count(s)==0){
			p.insert(s);
			a.push_back(s);
		}
	}
	p.clear();
	for(int i=1;i<=m;i++){
		cin>>s;
		if(p.count(s)==0){
			p.insert(s);
			b.push_back(s);
		}
	}
	p.clear();
	for(int i=0;i<min(a.size(),b.size());i++){
		if(a[i]==b[i]){
			p.insert(a[i]);
			cout<<a[i]<<endl;
		}
		else{
			if(p.count(a[i])==0){
				cout<<a[i]<<endl;
				p.insert(a[i]);
			}
			if(p.count(b[i])==0){
				cout<<b[i]<<endl;
				p.insert(b[i]);
			}
		}
	}
	for(int i=min(a.size(),b.size());i<max(a.size(),b.size());i++){
		if(a.size()>b.size()){
			if(p.count(a[i])==0){
				p.insert(a[i]);
				cout<<a[i]<<endl;
			}
		}
		else{
			if(p.count(b[i])==0){
				p.insert(b[i]);
				cout<<b[i]<<endl;
			}
		}
	}
	return 0;
}
相关推荐
Uitwaaien542 分钟前
51 单片机矩阵键盘密码锁:原理、实现与应用
c++·单片机·嵌入式硬件·51单片机·课程设计
网络风云17 分钟前
golang中的包管理-下--详解
开发语言·后端·golang
墨楠。29 分钟前
数据结构学习记录-树和二叉树
数据结构·学习·算法
小唐C++35 分钟前
C++小病毒-1.0勒索
开发语言·c++·vscode·python·算法·c#·编辑器
S-X-S41 分钟前
集成Sleuth实现链路追踪
java·开发语言·链路追踪
醇醛酸醚酮酯1 小时前
Leetcode热题——移动零
算法·leetcode·职场和发展
沉默的煎蛋1 小时前
MyBatis 注解开发详解
java·数据库·mysql·算法·mybatis
Aqua Cheng.1 小时前
MarsCode青训营打卡Day10(2025年1月23日)|稀土掘金-147.寻找独一无二的糖葫芦串、119.游戏队友搜索
java·数据结构·算法
夏末秋也凉1 小时前
力扣-数组-704 二分查找
算法·leetcode
玛丽亚后1 小时前
动态规划(路径问题)
算法·动态规划