字符串处理 Codeforces Round #285 (Div. 2) B. Misha and Changing Handles
/*
题意:给出一系列名字变化,问最后初始的名字变成了什么
字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,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的更多相关文章
- 图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest
题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...
- 水题 Codeforces Round #285 (Div. 2) C. Misha and Forest
题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...
- 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 ...
- Codeforces Round #285 (Div. 1) B - Misha and Permutations Summation 康拓展开+平衡树
思路:很裸的康拓展开.. 我的平衡树居然跑的比树状数组+二分还慢.. #include<bits/stdc++.h> #define LL long long #define fi fir ...
- 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 ...
- 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax
题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...
- 字符串处理 Codeforces Round #297 (Div. 2) B. Pasha and String
题目传送门 /* 题意:给出m个位置,每次把[p,len-p+1]内的字符子串反转,输出最后的结果 字符串处理:朴素的方法超时,想到结果要么是反转要么没有反转,所以记录 每个转换的次数,把每次要反转的 ...
- 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 ...
- 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 ...
随机推荐
- 新手玩个人server(阿里云)续二
小二班一番厮杀:那英四强诞生:大家闺秀,小家碧玉.窈窕淑女,妍姿俊俏 .不解释! ?不行! 陈冰,李嘉格,刘明湘.张碧晨.大多数的时候,仅仅要脸好看,一切都那么自热而然的顺理成章. 尽管网上骂声四起, ...
- 核函数以及SVM相关知识(重点)
http://www.cnblogs.com/jerrylead/archive/2011/03/18/1988406.html http://blog.pluskid.org/?p=685 考虑我们 ...
- [NPM] npm check to update the dependencies
To update the dependencies in the project, we can run: npx npm-check -u
- leetcode:122. Best Time to Buy and Sell Stock II(java)解答
转载请注明出处:z_zhaojun的博客 原文地址 题目地址 Best Time to Buy and Sell Stock II Say you have an array for which th ...
- iOS 开发者中的个人账号与组织账号之间区别
苹果对开发者主要分为3类:个人.组织(公司.企业).教育机构.即: 1.个人(Individual) 2.组织(Organizations) 组织类又分为2个小类: (1)公司(Company) (2 ...
- 关于 iOS 的 StoryBoard,接受的那一刻才发现她的美 - 当然美的事物都须要业心照料
关于 iOS 的 StoryBoard,接受的那一刻才发现她的美 - 当然美的事物都须要业心照料 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循&quo ...
- easyUI的tree
前端使用easyUI,放了一个tree,搞死了. easyUI的tree,后端传过来的数据,是json格式:然后easyUI向后端提交.请求时,会自动将节点的id附在url后面. 主要有两个注意的地方 ...
- 2016/3/26 weixin 头像 昵称 网页优化显示 缺表中数据 只有代码 无显示效果
weixin.php <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- 如何获取板子上独有的ID号EXYNOS4412/Imx6ul【转】
本文转载自:http://blog.csdn.net/u010871058/article/details/75637175 每个CPU,都有它固定的ID号,ID号就是这个CPU唯一的标识,它可能隐含 ...
- unbantu安装mysql
1,方法一 sudo apt-get install mysql-server apt isntall mysql-client apt install libmysqlclient-dev(暂不知用 ...