题目传送门

 /*
题意:给出一系列名字变化,问最后初始的名字变成了什么
字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,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. 【Todo】C++和Java里面的浮点数及各种数字表示

    今天看了这篇文章,是讲C++中的浮点类型的:<浮点数的二进制表示> 再复习一下Java里面的Float和Double. 首先,直接数字赋值给Float变量是不行的,数字后要加上F,这样写: ...

  2. django 简易博客开发 5 markdown支持、代码高亮、gravatar头像服务

    上一篇博客介绍了comments库使用及ajax支持,现在blog已经具备了基本的功能,但是只能发表文字,不支持富文本编辑.今天我们利用markdown添加富文本支持. markdown语法说明: h ...

  3. Manage, Administrate and Monitor GlassFish v3 from Java code usingAMX &amp; JMX

    http://kalali.me/manage-administrate-and-monitor-glassfish-v3-from-java-code-using-amx-jmx/ Manage, ...

  4. [Angular] Write Compound Components with Angular’s ContentChild

    Allow the user to control the view of the toggle component. Break the toggle component up into multi ...

  5. 容器使用笔记(List篇)

    上一篇博客介绍了Dictionary,这篇博客介绍List的相关内容. C#中要存储一组数据.我们会想到数组Array,ArrayList,List这三个对象,当中,数组是最早出现的,我们就从数组開始 ...

  6. webpack-Hot Module Replacement(热更新)

    模块热替换(Hot Module Replacement) 模块热替换(HMR - Hot Module Replacement)功能会在应用程序运行过程中替换.添加或删除模块,而无需重新加载整个页面 ...

  7. 怎样将查询到的数据显示在DataGridView中

    背景介绍: 数据库中的T_Line_Info表中存放着学生上机的记录,也就是我们须要查询上机记录的表.当中详细内容为: 界面设计例如以下: watermark/2/text/aHR0cDovL2Jsb ...

  8. Xcode中使用git

    项目中添加git 也可在开始新建项目时勾选git,这是针对开始没有勾选git的情况 打开终端 cd 项目文件目录 //初始化一个代码仓库, git init //将当前目录及子目录中的文件标记为要添加 ...

  9. 网页中打开exe

    网页上打开本地的exe文件,可以吗? 西蒙说:可以的. 方法如下: 1.定义一个私有协议,指向本地的那个exe 2.在网页上将此私有协议作为URL,点击之即可打开那个exe 3.URL中还可以包含参数 ...

  10. 安装linux各种桌面环境

    1.安装kde ①添加 KDE SC 4.11 库 打开一个终端窗口,在终端窗口中输入如下命令: sudo add-apt-repository ppa:kubuntu-ppa/backports 回 ...