字符串处理 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 ...
随机推荐
- Excel中INDEX函数的使用
1 函数INDEX( )有两种形式: 数组形式——INDEX(array,row_num,column_num)和 引用形式——INDEX(reference,row_num,column_num,a ...
- 16款创建CSS3动画的jQuery插件
jQuery插件是用来扩展jQuery原型对象的方法. 本文搜集了用来为你的站点创建CSS3动画的一些jQuery插件. 1. jQuery Smoove Smoove 简化了CSS3转换效果.使得页 ...
- MongoDB使用入门
1.MongoDB的安装 步骤一:下载MongoDB 下载安装包:http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.4.tgz 步骤二:设置 ...
- Intel为Google的物联网平台Brillo推出开发板Edison
Brillo* is a solution from Google* for building connected devices. Incorporating aspects of the Andr ...
- DDM的成熟在一个细微之处的体现
前言 我们都知道DDM是华为云的非常优秀的分布式数据库中间件,在性能.易用性等方面在业界是遥遥领先的.他的成熟不仅仅体现在具有快速水平平滑扩容,支持多种分布式事物类型等等这些高大上的特性上,也体现在D ...
- 微软Build2016:Xamarin杂记
去年的Build2015技术大会.留给人印象最深的莫过是Windows 10在手机端.PC端.Xbox等硬件平台上的大一统.还有非常具有科幻气质的HoloLens技术的各种展示.去年尽管也展示了Xam ...
- 在VC6.0中多线程编程演示样例(带同步信号量)
直接上代码: #include <windows.h>//必要的头文件,使用Windows API函数 #include <stdio.h> int index = 0; in ...
- 2016/3/18 ①PHP基础 ② PHP函数 ③其他函数(随机数、关于日期) ④正则表达式 ⑤字符串处理
一.PHP基础 1,标记和注释 ①<?php?> ②单行注释// 多行注释/** */2, 输出语句 ①echo输出 echo可以输出多个字符串,用逗号隔开. ②print输出 pr ...
- spring 简述
Spring的发展 1.1. Spring1.x 时代 在Spring1.x时代,都是通过xml文件配置bean,随着项目的不断扩大,需要将xml配置分放到不同的配置文件中,需要频繁的在java类和x ...
- UVA11183 Teen Girl Squad —— 最小树形图
题目链接:https://vjudge.net/problem/UVA-11183 You are part of a group of n teenage girls armed with cell ...