1121. Damn Single (25) 格式 map

简介: #include #include #include #include using namespace std;int main(){ int n, m; string a, b; cin...
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main(){
    int n, m;
    string a, b;
    cin >> n;
    vector <string> ans, t;
    map<string, string> ma;
    map<string, bool> mb;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        ma[a] = b;
        ma[b] = a;
    }

    cin >> m;
    for (int i = 0; i < m; i++) {
        cin >> a;
        t.push_back(a);
        mb[a] = 1;
    }
    for (int i = 0; i < m; i++) {
        if(!mb[ma[t[i]]]) ans.push_back(t[i]);
        //ma[t[i]] t[i]的配偶 mb判断其是否出现在聚会中
    }
    sort(ans.begin(), ans.end());

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        if(i != 0) cout << ' ';
        cout << ans[i];
    }
    //呵呵哒
    if (ans.size()) {
        cout << endl;
    }

    return 0;
}
目录
相关文章
Java 将Map的toString格式字符串转为 Map
Java 将Map的toString格式字符串转为 Map
1645 0
Java 将Map的toString格式字符串转为 Map
Spring-数组、List、Set、Map、Properties依赖注入格式
Spring-数组、List、Set、Map、Properties依赖注入格式
190 0
|
10月前
|
安全 Java 数据库连接
让我们讲解一下 Map 集合遍历的方式
我是小假 期待与你的下一次相遇 ~
352 43
Dart之集合详解(List、Set、Map)
Dart之集合详解(List、Set、Map)
241 1
|
存储 前端开发 API
ES6的Set和Map你都知道吗?一文了解集合和字典在前端中的应用
该文章详细介绍了ES6中Set和Map数据结构的特性和使用方法,并探讨了它们在前端开发中的具体应用,包括如何利用这些数据结构来解决常见的编程问题。
ES6的Set和Map你都知道吗?一文了解集合和字典在前端中的应用
|
存储 安全 Java
java集合框架复习----(4)Map、List、set
这篇文章是Java集合框架的复习总结,重点介绍了Map集合的特点和HashMap的使用,以及Collections工具类的使用示例,同时回顾了List、Set和Map集合的概念和特点,以及Collection工具类的作用。
java集合框架复习----(4)Map、List、set
|
Go 定位技术 索引
Go 语言Map(集合) | 19
Go 语言Map(集合) | 19
【Java集合类面试二十二】、Map和Set有什么区别?
该CSDN博客文章讨论了Map和Set的区别,但提供的内容摘要并未直接解释这两种集合类型的差异。通常,Map是一种键值对集合,提供通过键快速检索值的能力,而Set是一个不允许重复元素的集合。

热门文章

最新文章