codeforces 501 B Misha and Changing Handles 【map】
题意:给出n个名字变化,问一个名字最后变成了什么名字
先用map顺着做的,后来不对, 发现别人是将变化后的那个名字当成键值来做的,最后输出的时候先输出second,再输出first
写一下样例就好理解了
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; string a,b; int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int n;
map<string,string> mp;
cin>>n;
while(n--){
cin>>a>>b;
if(!mp.count(a)) mp[a]=a;
mp[b]=mp[a];
mp.erase(a);
} cout<<mp.size()<<"\n";
for(map<string,string>::iterator it=mp.begin();it!=mp.end();++it)
cout<<it->second<<" "<<it->first<<"\n";
return ;
}
唉,这么久才补,真是太懒了-------
加油啊-
goooooooo-------------------------------------------
codeforces 501 B Misha and Changing Handles 【map】的更多相关文章
- 【CodeForces - 501B 】Misha and Changing Handles(map)
Misha and Changing Handles CodeForces原题是英文,这里就直接上中文好了,翻译不是太给力,但是不影响做题 ^▽^ Description 神秘的三角洲里还有一个传说 ...
- 字符串处理 Codeforces Round #285 (Div. 2) B. Misha and Changing Handles
题目传送门 /* 题意:给出一系列名字变化,问最后初始的名字变成了什么 字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,pos[m] 数组记录初始位置 在每一次更新时都把初始pos加上 ...
- ACM Misha and Changing Handles
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user ...
- B. Misha and Changing Handles
B. Misha and Changing Handles time limit per test 1 second memory limit per test 256 megabytes input ...
- 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】
目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...
- 01 语言基础+高级:1-6 集合_day04【Map】
day04 [Map] 主要内容 Map集合 教学目标 能够说出Map集合特点 使用Map集合添加方法保存数据 使用”键找值”的方式遍历Map集合 使用”键值对”的方式遍历Map集合 能够使用Hash ...
- Codeforces Round #446 (Div. 2) A. Greed【模拟】
A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #428 A. Arya and Bran【模拟】
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #445 D. Restoration of string【字符串】
D. Restoration of string time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- 新手村,学会做人选数 https://www.luogu.org/problemnew/show/P1036
#include<cstdio> #include<cmath> #include<string.h> using namespace std; int n,k,s ...
- mfc进制转换
; CString str; m_edit1.GetWindowTextW(str); swscanf_s(str, _T("%d"), &num); _TCHAR str ...
- Java 以空格分割字符串
Java中使用类似于 str.split("/"); 的方法可以很方便的实现将一个字符串分割为数组, 但是如果分隔符是一个(或几个)空格呢?? 我们的本能反应或许应该是 str.s ...
- html5+css3+javascript 自定义提示窗口
效果图: 源码: 1.demo.jsp <%@ page contentType="text/html;charset=UTF-8" language="java& ...
- python 3.x 学习笔记10 (析构函数and继承)
1.类变量的用途:大家公用的属性,节省开销(内存) 2.析构函数 在实例释放和销毁的时候执行的,通常用于做一些收尾工作,如关闭一些数据库链接和打开的临时文件 3.私有方法两个下划线开头,声明该方法为私 ...
- MyBatis数据持久化(三)增删改查
上篇文章中我们使用mybatis成功建立数据库会话,并从表中查询出相应的数据,本文在此基础上介绍MyBatis另外几种操作,即插入.修改.删除记录. 1.修改User.xml文件,增加几条sql语句: ...
- (转载)Android:学习AIDL,这一篇文章就够了(上)
前言 在决定用这个标题之前甚是忐忑,主要是担心自己对AIDL的理解不够深入,到时候大家看了之后说——你这是什么玩意儿,就这么点东西就敢说够了?简直是坐井观天不知所谓——那样就很尴尬了.不过又转念一想, ...
- JavaScript学习——使用JS实现首页轮播图效果
1.相关技术 获取元素 document.getElementById(“id 名称”) 事件(onload) 只能写一次并且放到body标签中 定时操作:setInterval(“changeImg ...
- 优动漫PAINT-朱槿花的画法
火红夺目的朱槿花,绝对是烘托画面的绝佳布景!画法发非常简单,毫无绘画基础的人也能够将它很好的呈现出来哟~ 教程是简单,呃.... 没有优动漫PAINT软件肿么办? 别着急,╭(╯^╰)╮ 小编给你送来 ...
- Dapper基础知识三
在下刚毕业工作,之前实习有用到Dapper?这几天新项目想用上Dapper,在下比较菜鸟,这块只是个人对Dapper的一种总结. Dapper,当项目在开发的时候,在没有必要使用依赖注入的时候,如何做 ...