G. I love Codeforces

题目大意:给你n个字符串,以及m个喜欢关系,如果u喜欢v,这时候u会把它的用户名改为 I_love_ 加上v当时的用户名

Examples
input
5
anonymous
natalia
LeBron
Tanya_Romanova
MikeMirzayanov
6
1 2
3 4
2 1
4 3
1 4
3 2
output

Copy
I_love_I_love_I_love_Tanya_Romanova

思路:

SB模拟题,纯模拟会出MLE,RE,TLE等锅,只需要记录每个点喜欢(I_love_)的个数,以及每个点对应的最后一个点。

需要注意一下:如果要使用printf输出字符串,需按如下方式输出:

string S;
printf("%s",S.c_str());

输入带有空格的字符串

#include<string>
string str;
getline(cin,str);

接收一个字符串,可以接收空格并输出

#include <iostream>
using namespace std;
int main () {
char m[];
cin.getline(m,);
cout<<m<<endl;
}

注意事项:

1、cin.getline()属于istream流,而getline()属于string流,是不一样的两个函数

2、当同时使用cin>>,getline()时,需要注意的是,在cin>>输入流完成之后,getline()之前,需要通过

str="\n";
getline(cin,str);

的方式将回车符作为输入流cin以清除缓存,如果不这样做的话,在控制台上就不会出现getline()的输入提示,而直接跳过,因为程序默认地将之前的变量作为输入流。

参考博文:https://www.cnblogs.com/AndyJee/archive/2014/07/02/3821067.html

MrBlue_and_MrGreen

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; int n,m,p[],sum[];
string s[],S="I_love_"; void add(int u,int v){
p[u]=p[v];sum[u]=sum[v]+;
} int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) cin>>s[i];
scanf("%d",&m);
for(int i=;i<=n;i++) p[i]=i;
for(int i=;i<=m;i++){
int a,b;
scanf("%d%d",&a,&b);
add(a,b);
}
for(int i=;i<=sum[];i++) printf("%s",S.c_str());
printf("%s",s[p[]].c_str());
return ;
}

G. I love Codeforces的更多相关文章

  1. 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  2. Asia Yokohama Regional Contest 2018 G题 What Goes Up Must Come Down

    链接 G题 https://codeforces.com/gym/102082 使其成为单峰序列需要交换多少次相邻的数. 树状数组维护逆序对. 对于每个序列中的数,要么在单峰的左侧,要么在单峰的右侧, ...

  3. Codeforces Round #790 (Div. 4) A-H

    Codeforces Round #790 (Div. 4) A-H A 题目 https://codeforces.com/contest/1676/problem/A 题解 思路 知识点:模拟. ...

  4. BUPT2017 wintertraining(15) #1 题解

    拖了一周才完成的题解,抛出一个可爱的表情 (っ'-')╮ =͟͟͞͞❤️.对我来说E.F比较难,都是线段树的题,有点久没写了. A - Infinite Sequence CodeForces - 6 ...

  5. 2017, X Samara Regional Intercollegiate Programming Contest 题解

    [题目链接] A - Streets of Working Lanterns - 2 首先将每一个括号匹配串进行一次缩减,即串内能匹配掉的就匹配掉,每个串会变成连续的$y$个右括号+连续$z$个左括号 ...

  6. 苏州大学ICPC集训队新生赛第二场

    A - Score UVA - 1585 水 #include<bits/stdc++.h> using namespace std; int main(){ int n; cin> ...

  7. Storyboards Tutorial 03

    这一节主要介绍segues,static table view cells 和 Add Player screen 以及 a game picker screen. Introducing Segue ...

  8. 文件图标SVG

    ​<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink ...

  9. codeforces 659 G. Fence Divercity 组合数学 dp

    http://codeforces.com/problemset/problem/659/G 思路: f(i,0/1,0/1) 表示到了第i个,要被切的块开始了没有,结束了没有的状态的方案数 递推看代 ...

随机推荐

  1. whl 安装

    pymssql 安装 C:\Users\sas>pip install d:\pymssql--cp36-cp36m-win_amd64.whl Processing d:\pymssql--c ...

  2. case when进行数据统计

    SELECT SUM(CASE WHEN `status` = '1' THEN 1 ELSE 0 END) AS waitpay, SUM(CASE WHEN `group_done` = '1' ...

  3. 【POJ 2018】 Best Cow Fences

    [题目链接] http://poj.org/problem?id=2018 [算法] 二分平均值 检验时将每个数减去二分的值,求长度至少为L的子序列和的最大值,判断是否大于0 [代码] #includ ...

  4. Makefile 实际用例分析(一) ------- 比较通用的一种架构

    这里不再说Makefile的基本知识,如果需要学习,那么请参考: 下载:makefile 中文手册 或者 点击打开链接 或者 跟我一起写Makefile( 陈皓 ) 这里说的是一般的实际的一个工程应该 ...

  5. 仪表盘(Speedometer) icon 设计

  6. js将字符串中所有反斜杠\替换成正斜杠/

    区分正斜杠与反斜杠: 正斜杠:http://.http紧跟着的斜杠,离手输入最近的斜杠,shift中间斜杠.45度角斜杠.正斜杠不需要转义 反斜杠:回车与空格之间.程序表示时需要转义成\\. str. ...

  7. dubbo+zookeeper下生产者和消费者配置(基于springboot开发)

    一.总共分为三个目录: dubbo-api      服务的接口用于对接客户端和服务端 dubbo-client     客户端配置文件为:consumer.xml dubbo-service  服务 ...

  8. 51nod 1340 差分约束

    思路: 带未知量的Floyd 很强 http://yousiki.net/index.php/archives/87/ //By SiriusRen #include <bits/stdc++. ...

  9. Win10中的睡眠、休眠

    共同点: 都是节能技术. 异同点: 睡眠: 需要耗电.通过键盘鼠标唤醒.唤醒速度快.将用户正在处理的数据保存到内存中,除内存以外的所有设备都停止供电. 休眠: 不需耗电.通过电源键唤醒.唤醒速度慢.将 ...

  10. [ USACO 2018 OPEN ] Out of Sorts (Silver)

    \(\\\) \(Description\) 运行以下代码对一长为\(N\)的数列\(A\)排序,不保证数列元素互异: cnt = 0 sorted = false while (not sorted ...