题目传送门

 /*
题意:给出一系列名字变化,问最后初始的名字变成了什么
字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,pos[m] 数组记录初始位置
在每一次更新时都把初始pos加上去,那么就保证更新了初始的名字,这也是唯一要思考的地方了:)
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <ctime>
using namespace std; const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
string old[MAXN];
string change[MAXN];
string ans[MAXN];
int pos[MAXN]; int main(void) //Codeforces Round #285 (Div. 2) B. Misha and Changing Handles
{
freopen ("B.in", "r", stdin); int n;
while (scanf ("%d", &n) == )
{
memset (pos, , sizeof (pos));
string tmp; int m = ;
for (int i=; i<=n; ++i)
{
cin >> tmp; cin >> change[i];
bool ok = false;
for (int j=; j<i; ++j)
{
if (tmp == change[j])
{
ok = true;
ans[pos[j]] = change[i];
pos[i] = pos[j]; break;
}
}
if (!ok)
{
old[++m] = tmp; ans[m] = change[i]; pos[i] = m;
}
} printf ("%d\n", m);
for (int i=; i<=m; ++i)
{
cout << old[i] << " " << ans[i] << endl;
}
} // cout << "time: " << (double) clock () / CLOCKS_PER_SEC * 1000 << " ms\n"; return ;
}

字符串处理 Codeforces Round #285 (Div. 2) B. Misha and Changing Handles的更多相关文章

  1. 图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest

    题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...

  2. 水题 Codeforces Round #285 (Div. 2) C. Misha and Forest

    题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...

  3. Codeforces Round #285 (Div. 1) A. Misha and Forest 拓扑排序

    题目链接: 题目 A. Misha and Forest time limit per test 1 second memory limit per test 256 megabytes 问题描述 L ...

  4. Codeforces Round #285 (Div. 1) B - Misha and Permutations Summation 康拓展开+平衡树

    思路:很裸的康拓展开.. 我的平衡树居然跑的比树状数组+二分还慢.. #include<bits/stdc++.h> #define LL long long #define fi fir ...

  5. Codeforces Round #285 (Div. 2)C. Misha and Forest(拓扑排序)

    传送门 Description Let's define a forest as a non-directed acyclic graph (also without loops and parall ...

  6. 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

    题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...

  7. 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String

    题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...

  8. Codeforces Round #285 (Div. 2) A B C 模拟 stl 拓扑排序

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  9. Codeforces Round #285 (Div. 2) A, B , C 水, map ,拓扑

    A. Contest time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

随机推荐

  1. centos6.5 (linux) 禁用模块 IPV6模块的方法

    装完centos后,默认开启了一些模块.可是有些模块并非我们必须的.比方眼下尚未在中国普及的IPV6 怎样关闭IPV6呢 以下介绍的方法,也能够在关闭其它模块的时候使用 第一步: 查找模块名称 使用命 ...

  2. 简单了解eMMC

    以下只是个人看法,有不妥之处,请批评指出. 参考资料:http://www.veryarm.com/1200.html 一.eMMC的发展 ROM→NorFlash→NandFlash→eMMC→UF ...

  3. JavaScript语句-流程控制语句

    JavaScript定义了一组语句,语句通常用于执行一定的任务.语句可以很简单,也可以很复杂. 选择结构,可以在程序中创建交叉结构来指定程序流的可能方向.JavaScript中有四种选择结构: 1.单 ...

  4. 【iOS系列】-UITableViewCell的展开与收缩的实现思路

    UITableViewCell的展开与收缩的实现思路 现在项目中很多地方都会用到,所以我这里介绍一种可以复用的思路,这与文章后面的Swift的实现思路不同,具体大家可自行对比. Demo项目地址 开始 ...

  5. 【iOS系列】- UITableView的使用技巧

    [iOS系列]- UITableView的使用 UITableView的常用属性 indexpath.row:行 indexpath.section:组 separatorColor:分割线的颜色 s ...

  6. wget和curl

    1 curl比wget支持更多的协议 2 wget是支持递归的,而curl不支持

  7. python 线程 进程 标识

    s = '%s%s%s%s%s%s%s%s' % ( time.strftime('%Y%m%d %H:%M:%S', time.localtime(time.time())), ' os.getpp ...

  8. Latex 3: 解决LaTeX编译卡顿问题

    1.问题: 最近在编译latex时,老是在tulmr.fd处编译很久,但是以前不这样啊,那肯定就是我最近做了什么导致这样的了,是什么呢? 2.解决: 后来google下发现了解决办法,原来是我新安装了 ...

  9. apache配置访问限制

    1.禁止访问某些文件/目录 增加Files选项来控制,比如要不允许访问 .txt扩展名的文件,保护php类库: <Files ~ "\.txt$"> Order all ...

  10. windows exe程序点击可以运行,但任务计划时程序不运行

    问题描述:exe程序双击或者cmd执行都可以,但是配置了计划任务就一闪而过,并没有对应log产生.                  可能会有和我同样的问题的小伙伴,这里记录一下. 解决方法:来在St ...