map<虽然一直不喜欢map>但突然觉得挺好用的

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cstdio>
#include<list>
#include<sstream>
//#include<regex>
using namespace std;
typedef long long ll;
int INF=2147483647;
int inf=-2147483648;
#define mod 1000000007;
#define read(x) scanf("%d",&x);
#define fo(i,n) for(int i=0;i<(n);i++)
#define me(a) memset(a,0,sizeof(a));
#define one(x) cout<<(x)<<endl;
#define two(a,b) cout<<(a)<<" "<<(b)<<endl;
#define three(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl;
#define four(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl;
//int dir[4][2]={0,1,0,-1,1,0,-1,0};
//int dir[8][2]={-1,0,1,0,0,-1,0,1,-1,-1,1,1,1,-1,-1,1};
//int dir[4][2]={-2,0,2,0,0,-2,0,2};
//int dir[6][3]={0,0,1,0,0,-1,0,1,0,0,-1,0,1,0,0,-1,0,0};
const double PI = acos(-1.0);
int main()
{
    ios::sync_with_stdio(false);
    int n;
    string a,b;
    map<string,string>q;
    map<string,string>::iterator it;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        if(q.count(a)==0){
            q[a]=a;
        }
        q[b]=q[a];
        q.erase(a);
    }
    cout<<q.size()<<endl;
    for(it=q.begin();it!=q.end();it++){
        cout<<it->second<<" "<<it->first<<endl;
    }
    cout<<endl;
    return 0;
}
时间: 2024-08-01 06:27:14

map<虽然一直不喜欢map>但突然觉得挺好用的的相关文章

java基础-Map的静态初始化以及Map的遍历等.....................

1.map的静态初始化,以及map遍历的几种方法: package com.cy.test; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; public class Test { public static void main(String[] args) { Map<String, Integer> map = new HashMap

java如何对map进行排序详解(map集合的使用)

今天做统计时需要对X轴的地区按照地区代码(areaCode)进行排序,由于在构建XMLData使用的map来进行数据统计的,所以在统计过程中就需要对map进行排序. 一.简单介绍Map 在讲解Map排序之前,我们先来稍微了解下map.map是键值对的集合接口,它的实现类主要包括:HashMap,TreeMap,Hashtable以及LinkedHashMap等.其中这四者的区别如下(简单介绍): HashMap:我们最常用的Map,它根据key的HashCode 值来存储数据,根据key可以直接

实现jsp页面两级列表的显示(Map 传值到Jsp 页面;Map去key 和 value 的方法; 实例记载,备不时之需。

Action: List.vm 页面效果: 实现jsp页面两级列表的显示(Map 传值到Jsp 页面;Map去key 和 value 的方法: 实例记载,备不时之需.

Could not find parameter map com.itcast.mapper.userinfMapper.map

问题?org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.  Cause: org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map com.itcast.mapper.userinfMapper.map ### Cause: org.apache.ibatis.builder.Inc

map泛型 map不指定泛型 与 Map&lt;Object,Object&gt;的区别

map泛型 map不指定泛型 与 Map<Object,Object>的区别 private void viewDetail(){ Map map1 = new HashMap(); Map<String,Object> map2 = new HashMap<String,Object>(); Map<Object,Object> map3 = new HashMap<Object,Object>(); Map<String,String&

封装的函数ClearAllData() 清空地图文档并新建mainMapControl中Map以及新建EagleEyeMapControl中Map

private void ClearAllData() { if (mainMapControl.Map != null && mainMapControl.Map.LayerCount > 0) { //新建mainMapControl中Map IMap dataMap = new MapClass(); dataMap.Name = "Map"; mainMapControl.DocumentFilename = string.Empty;//Document

把List&lt;Map&lt;String,Object&gt;&gt;转成Map&lt;String,Object&gt;

Map<String, Object> parmMap = new HashMap<String, Object>(); //定义一个用于存储强转后的Map List<Map<String, Object>> findActivityList = groupConfigDao.findActivityList(); //查询List<Map>里的数据 //List<Map<String, Object>> (findAct

c++map按value排序--将map的pair对保存到vector中,然后写比较仿函数+sort完成排序过程。

map是用来存放<key, value>键值对的数据结构,可以很方便快速的根据key查到相应的value.假如存储学生和其成绩(假定不存在重名,当然可以对重名加以区分),我们用map来进行存储就是个不错的选择. 我们这样定义,map<string, int>,其中学生姓名用string类型,作为Key:该学生的成绩用int类型,作为value.这样一来,我们可以根据学生姓名快速的查找到他的成绩. 但是,我们除了希望能够查询某个学生的成绩,或许还想看看整体的情况.我们想把所有同学和他

分页查询和分页缓存查询,List&lt;Map&lt;String, Object&gt;&gt;遍历和Map遍历

分页查询 String sql = "返回所有符合条件记录的待分页SQL语句"; int start = (page - 1) * limit + 1; int end = page * limit; sql = "select * from (select fulltable.*, ROWNUM RN from (" + sql + ") fulltable where ROWNUM <= " + end + ") where