VK Cup 2015 - Qualification Round 1 A. Reposts(map最大连续长度)
2015-03-26 20:28
239 查看
A. Repoststime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.InputThe first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.OutputPrint a single integer — the maximum length of a repost chain.Sample test(s)input
5 tourist reposted Polycarp Petr reposted Tourist WJMZBMR reposted Petr sdya reposted wjmzbmr vepifanov reposted sdyaoutput
6input
6Mike reposted PolycarpMax reposted PolycarpEveryOne reposted Polycarp111 reposted PolycarpVkCup reposted PolycarpCodeforces reposted Polycarpoutput
2input
1 SoMeStRaNgEgUe reposted PoLyCaRpoutput2给出3个字符串a,b,c a转帖于c 问从 Polycarp 出发,到转帖的最后一个人的最大长度,一开始用map的时候,是以被转帖人的名字为下标的,结果输入的时候只保存了最后一个Polycarp转帖人名字,果断WA了,其实以每个转帖人的名字为下标,来记录当前长度即可所有名字不区分大小写
#include <cstdio> #include <cstring> #include <stdlib.h> #include <iostream> #include <algorithm> #include <queue> #include <map> #define inf 0x3f3f3f3f #define N 30 using namespace std; char a ,b ,c ; int main() { int n; while(~scanf("%d",&n)) { map<string,int>q; q["POLYCARP"]=1; int ans=0; for(int i=0; i<n; i++) { scanf("%s%s%s",a,b,c); int len1=strlen(a); for(int j=0; j<len1; j++) { if(a[j]>='a' && a[j]<='z') a[j]-=32; } int len2=strlen(c); for(int j=0; j<len2; j++) { if(c[j]>='a' && c[j]<='z') c[j]-=32; } q[a]=q[c]+1; ans=max(ans,q[a]); } printf("%d\n",ans); } return 0; }
相关文章推荐
- 客户端C和服务器S之间建立了一个TCP连接,TCP最大段长度为1KB,客户端C当前的拥塞窗口是16KB,向服务器S连续发送2个最大段之后,成功收到服务器S发送的第一段的确认段,确认段中通告的接受窗口大
- Map的value最大长度值
- 【Leetcode】寻找数串中连续最大整数和且最大长度的子串
- 《一道笔试题》找出最连续数字的最大长度
- VK Cup 2015 - Qualification Round 1 A. Reposts(树)
- 数组最大连续长度
- 风口之下,猪都能飞。当今中国股市牛市,真可谓“错过等七年”。 给你一个回顾历史的机会,已知一支股票连续n天的价格走势,以长度为n的整数数组表示,数组中第i个元素(prices[i])代表该股票第i天的股价。 假设你一开始没有股票,但有至多两次买入1股而后卖出1股的机会,并且买入前一定要先保证手上没有股票。若两次交易机会都放弃,收益为0。 设计算法,计算你能获得的最大收益。 输入数值范围:2<=n<
- VK Cup 2015 - Qualification Round 1 A. Reposts(树)
- 最大连续长度不超过m的子序列和
- VK Cup 2015 - Qualification Round 1 A. Reposts [ dp DAG上最长路 ]
- hdu 1540 线段树 点所在的区间最大连续长度
- Longest Substring Without Repeating Characters计算字符串中不含有重复字符的连续字符串的最大长度
- 求一个序列的最大连续长度
- [阿里2015校招笔试]求字符串query和text最长连续字母序列的长度
- 【HDU5583 2015上海赛区K】【暴力合并】Kingdom of Black and White 连续01串权值贡献为len^2最多改变一次最大权值
- C++_USACO_求一个字符串的连续相同字符的最大长度
- 求两个字符串的最大公共子序列(可以不连续)的长度,并输出这个子序列
- 字符串中不重复连续字符子串的长度最大值
- 原串与其逆序串 对应位置且 连续最大长度
- leetcode寻找最大长度的连续数对