VK Cup 2015 - Qualification Round 1, problem: (A) Reposts 【map】

题意

转发帖子问题,A reposted B
A代表转发人,B代表发帖人,求最大转发链长度

思路

将所有人统一用户名为小写,然后用map记录当前转发人,每次比较求出最大值

code

#include<bits/stdc++.h>
using namespace std;
int n;
string s1,s2;
map<string,int> mp;
int main(){
    cin>>n;
    mp["polycarp"]=1;
    int cnt=0;
    for(int i=0;i<n;i++){
        cin>>s1>>s2>>s2;
        for(int j=0;j<s1.length();j++)
            s1[j]=tolower(s1[j]);
        for(int j=0;j<s2.length();j++)
            s2[j]=tolower(s2[j]);
        mp[s1]=mp[s2]+1;
        cnt=max(cnt,mp[s1]);
    }
    cout<<cnt<<endl;
    return 0;
}
学如逆水行舟,不进则退
发布了407 篇原创文章 · 获赞 954 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/weixin_42429718/article/details/104098214