VK Cup 2015 - Qualification Round 1 A. Reposts(樹)

傳送門

Description

One 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.

Input

The 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.

Output

Print a single integer — the maximum length of a repost chain.

Sample Input

5
tourist reposted Polycarp
Petr reposted Tourist
WJMZBMR reposted Petr
sdya reposted wjmzbmr
vepifanov reposted sdya

6
Mike reposted Polycarp
Max reposted Polycarp
EveryOne reposted Polycarp
111 reposted Polycarp
VkCup reposted Polycarp
Codeforces reposted Polycarp

1
SoMeStRaNgEgUe reposted PoLyCaRp

Sample Output

6

2

2

思路

題解:

?

?

#include<bits/stdc++.h>
using namespace std;
const int maxn = 205;
char str[maxn],a[maxn],b[maxn];int main(){int n,res = 0;map<string,string>mp;set<string>s;set<string>::iterator it;scanf("%d",&n);getchar();for (int i = 0;i < n;i++){gets(str);int j = 0,len = strlen(str);for (j = 0;str[j] != ' ';j++){if (str[j] >= 65 && str[j] <= 90){str[j] += 32;}}strncpy(a,str,j);for (j = len - 1; str[j] != ' ';j--){if (str[j] >= 65 && str[j] <= 90){str[j] += 32;}}strncpy(b,str + j + 1,len - 1 - j);s.insert(a),s.insert(b);mp[a] = b;memset(a,0,sizeof(a));memset(b,0,sizeof(b));}for (it = s.begin();it != s.end();it++){int len = 1;string val = *it;while (mp.count(val))	val = mp[val],len++;res = max(res,len);}printf("%d\n",res);return 0;
}

  

轉載于:https://www.cnblogs.com/ZhaoxiCheung/p/7309589.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/282814.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/282814.shtml
英文地址,請注明出處:http://en.pswp.cn/news/282814.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Lombok@Builder和@NoArgsConstructor沖突

問題 今天在使用lombok簡化model類時。使用Builder建造者模式。報以下異常 解決辦法。 去掉NoArgsConstructor添加AllArgsConstructor源碼分析 下圖是編譯后的源碼 只使用Builder會自動創建全參構造器。而添加上NoArgsConstructor后就不會自動產生全參構造器

現在商業有種競爭叫“跨界打擊”

隨著互聯網的發展&#xff0c;“跨界打擊”的事情可謂是無處不在。行業跨界打擊會搶占某個行業的市場份額&#xff0c;甚至可能淘汰一個行業。跨界打擊者可能是某個行業的新進入者&#xff0c;也可能是現有競爭者&#xff0c;更可能是徹底的替代者或顛覆者。跨界打擊&#xff0…

架構之美閱讀筆記之一

寒假生活開始了&#xff0c;關于軟件架構這部分的學習&#xff0c;我選擇的是《架構之美》這本書。這本出版于2009年的書&#xff0c;由淺入深地講述了從架構的概述&#xff0c;到企業級應用架構&#xff0c;系統架構&#xff0c;最終用戶應用架構&#xff0c;再到語言與架構模…

ntop linux,Linux下開源監控軟件Ntop的性能提升方案

摘要&#xff1a;Ntop是一款Linux下常見的開源監控軟件&#xff0c;它可以監測的數據包括&#xff1a;網絡流量、使用協議、系統負載、端口情況、數據包發送時間等。正常情況下它工作的時候就像一部被動聲納&#xff0c;默默的接收看來自網絡的各種信息&#xff0c;通過對這些數…

Java異常處理教程

異常是在沒有定義正常執行路徑時在Java程序的執行期間可能出現的條件。Java通過將執行操作的代碼與處理錯誤的代碼分離來處理錯誤。 當發生異常時&#xff0c;Java會創建一個包含有關異常的所有信息的對象&#xff0c;并將其傳遞給相應的異常處理代碼。有關異常的信息包括異常的…

性能優化8--內存泄露

一.根源&#xff1a; 內存泄露簡單說就是已經沒有用的資源&#xff0c;但是由于被其他資源引用著無法被GC銷毀。 二.內存泄露常見場景 1.單例導致內存泄露 單例的靜態特性使得它的生命周期同應用的生命周期一樣長&#xff0c;如果一個對象已經沒有用處了&#xff0c;但是單例還…

那些年,登山徒步記錄,立貼

2018年1月-9月份暫無數據。&#xff08;慘無人道&#xff0c;已經喪失了自我。&#xff09; 10月份2017年2月份02月12日 25.00KM 牛木外線3月份暫無數據。 4月份1.04月09日 16.00KM 火鳳線 5月份1.05月06日 20.00KM 漁帽線&#xff08;第一機耕路&#xff09; 6月份1.06月11日 …

記一次 .NET 某打印服務 非托管內存泄漏

一&#xff1a;背景 1. 講故事前段時間有位朋友在微信上找到我&#xff0c;說他的程序出現了內存泄漏&#xff0c;能不能幫他看一下&#xff0c;這個問題還是比較經典的&#xff0c;加上好久沒上非托管方面的東西了&#xff0c;這篇就和大家分享一下&#xff0c;話不多說&#…

android靜態方法如何測試,android – 如何使用mock()和spy()測試靜態方法

通常情況下,如果你最終使用PowerMock,這是一個很好的跡象,表明你最有可能是錯誤的方式.如果不是直接引用畢加索,而是創建一個組件,它的職責是加載圖像,讓我們說類ImageLoader.這會給你什么&#xff1f;>關注點分離&#xff1a;如果明天你決定轉移到Glide,你不應該改變你使用…

mysql經典的8小時問題-wait_timeout

2019獨角獸企業重金招聘Python工程師標準>>> 前段時間 現網突然頻繁報出 連接不上數據庫&#xff0c;偶滴的妖孽&#xff0c;其他地方都是用mysql&#xff0c;也沒遇到這個問題呀。 java.io.EOFExceptionat at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1913…

Chrome DevTools — Network

記錄網絡請求 默認情況下&#xff0c;只要DevTools在開啟狀態&#xff0c;DevTools會記錄所有的網絡請求&#xff0c;當然&#xff0c;記錄都是在Network面板展示的。 停止記錄網絡請求 點擊Stop recording network log紅色圖標&#xff0c;當它變為灰色時&#xff0c;表示DevT…

Blazor University 中文版網站已上線

在學習 Blazor 的過程中&#xff0c;找到了一個網站 Blazor University&#xff08;https://blazor-university.com&#xff09;。發現網站內容非常詳實&#xff0c;正像首頁所說的&#xff1a;通過瀏覽本網站中的信息&#xff0c;我打算帶您從完全的新手到Blazor的所有方面的專…

android:paddingtop 百分比,相對層中的百分比寬度

相對層中的百分比寬度我正在為登錄進行表單布局。Activity在我的Android應用程序中。下面的圖片是我希望它看起來的樣子&#xff1a;我能夠通過以下方式實現這個布局XML..問題是&#xff0c;這有點麻煩。我不得不對主機EditText的寬度進行硬編碼。具體而言&#xff0c;我必須具…

MySQL 查看表結構簡單命令

一、簡單描述表結構&#xff0c;字段類型 desc tabl_name; 顯示表結構&#xff0c;字段類型&#xff0c;主鍵&#xff0c;是否為空等屬性&#xff0c;但不顯示外鍵。 例如&#xff1a;desc table_name 二、查詢表中列的注釋信息 select * from information_schema.columns wher…

簡單獲取任意app的URL Schemes

簡單說明 最近業務需要&#xff0c;一直在查詢App的scheme相關信息&#xff0c;找到一種比較可靠的方法&#xff0c;分享給大家 步驟如下&#xff1a; 在電腦上使用iTunes下載那個app下載完后&#xff0c;在itunes里點擊這個app&#xff0c;選擇->Show in Finder&#xff0c…

Java中short、int、long、float、double的取值范圍

一、基本數據類型的特點&#xff0c;位數&#xff0c;最大值和最小值。1、基本類型&#xff1a;short 二進制位數&#xff1a;16 包裝類&#xff1a;java.lang.Short 最小值&#xff1a;Short.MIN_VALUE-32768 &#xff08;-2的15此方&#xff09;最大值&#xff1a;Short.MAX_…

.Net之接口文檔精度丟失處理

目的最近兩天在給朋友講解如何使用ajax調用接口時候&#xff0c;我發現我用swagger調用接口返回的long類型的數據最后幾位都變成了0(例如&#xff1a;6974150586715898000)&#xff0c;本來是以為sqlite數據庫不支持long類型導致我存進去的數據出了問題&#xff0c;然后我使用接…

android 訪問sqlite,android中訪問已有的sqlite數據庫

推薦文章每天進步記錄一點點話說經常性的操作svn出現各種問題,而度娘一直幫倒忙,是不是很手足無措.有時問題還是要記錄下來的.說不定還會有驚喜. 昨天遇到個問題,搜索了一下,發現第一條就是自己寫的.驚呆我了,更驚呆我的是,我是在csdn寫的,為什么在別的網站看到,完全一模一樣..…

Dnslog在SQL注入中的利用

參考文獻&#xff1a;www.anquanke.com/post/id/98096https://bbs.pediy.com/thread-223881.htm DNSlog在Web攻擊的利用 在某些無法直接利用漏洞獲得回顯的情況下&#xff0c;但是目標可以發起DNS請求&#xff0c;這個時候就可以通過DNSlog把想獲得的數據外帶出來。 常用情況 S…

讓泛型的思維扎根在腦海——深刻理解泛型

1.前言往往一些剛接觸C#編程的初學者&#xff0c;對于泛型的認識就是直接跳到對泛型集合的使用上&#xff0c;雖然微軟為我們提供了很多內置的泛型類型&#xff0c;但是如果我們只是片面的了解調用方式&#xff0c;這會導致我們對泛型盲目的使用。至于為什么要使用泛型&#xf…