题目传送门

 /*
题意:给出一系列名字变化,问最后初始的名字变成了什么
字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,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. html 元素定位position-relative, absolute, fixed, static

    看到这个,你有什么想法? Difference between static and relative positioning 如果你能完全看明白,那几本上css 元素定位的东西基本都会了.本文也不用 ...

  2. Android +NDK+eclipse+opengl ES2.0 开启深度測试

    參考:https://www.opengl.org/discussion_boards/showthread.php/172736-OpenGL-ES-Depth-Buffer-Problem 环境: ...

  3. [数据集]新浪微博数据集MicroblogPCU

    数据集下载地址:下载 摘要:MicroblogPCU是从新浪微博採集到的.它能够被用于研究机器学习方法和社会关系研究. 这个数据集被原作者用于探索微博中的spammers(发送垃圾信息的人).他们的d ...

  4. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第10章节--SP2013中OAuth概览 总结

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第10章节--SP2013中OAuth概览  总结         SP2013中的OAuth提供了很多新的集成SP On ...

  5. 3.2.1 配置构建Angular应用——简单的笔记存储应用——展示功能

    本节我们会通过构建一个简单的笔记存储应用(可以载入并修改一组简单的笔记)来学习如何应用Angular的特性.这个应用用到的特性有: 在JSON文件中存储笔记 展示.创建.修改和删除笔记 在笔记中使用M ...

  6. Android:内存控制及OOM处理

      1. OOM(内存溢出)和Memory Leak(内存泄露)有什么关系? OOM可能是因为Memory Leak,也可能是你的应用本身就比较耗内存(比如图片浏览型的).所以,出现OOM不一定是Me ...

  7. 浅谈JavaScript的字符串的replace方法

    JavaScript字符串提供了一个replace方法.replace方法可以接受两个参数:第一个参数可以使RegExp对象或者一个字符串,第二个参数可以是一个字符串或者一个函数.如果第一个参数是字符 ...

  8. sizeof、strlen

    一.sizeof sizeof(...)是运算符,sizeof操作符的结果类型是size_t.它在头文件里typedef为unsigned int类型.是以字节为单位进行计数的.所以位域成员不 能用s ...

  9. Android-shareSDK

    1.当数据: 地址:http://sharesdk.mob.com/Download 2.集成数据: DOS命令: java -jar QuickIntegrater.jar    (输入自己的项目名 ...

  10. WIN7 不用格式化磁盘怎么把FAT32系统改成NTFS系统

    开始-运行,输入cmd回车.假设你要转换D盘.输入convert d: /fs:NTFS回车. [ 此时可能会提示: 访问被拒绝 因为你没有足够的特权 是权限不够的原因 开始--程序--附件 右键&q ...