zoukankan      html  css  js  c++  java
  • P2814 家谱

    map记录,

    if(a[s]=="") 注意不是空格,意思是当他还没有父亲时。

    char输入还是用cin吧。

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    #include<map>
    using namespace std;
    
    char ch;
    string s,s1;
    map<string,string>a;
    
    string find(string x)
    {
    	if(a[x]==x) return x;
    	else return a[x]=find(a[x]);
    }
    
    int main()
    {
    	cin>>ch;
    	while(ch!='$')
    	{
    		cin>>s;
    		if(ch=='#')
    		{
    			s1=s;
    			if(a[s]=="") a[s]=s;
    		}
    		else if(ch=='+')
    			a[s]=s1;
    		else cout<<s<<" "<<find(a[s])<<endl;
    		cin>>ch;
    	} 
    	return 0;
    }
    

    如果你不开心,那我就把右边这个帅傻子分享给你吧,   

    你看,他这么好看,那么深情的望着你,你还伤心吗?   

    真的!这照片盯上他五秒钟就想笑了。   

    一切都会过去的。  

  • 相关阅读:
    重启机器导致mysql启动失败
    setTimeout 的方式实现 setInteval
    4.1 k8s-pod的基本操作
    Git
    leetcode -1
    面试-总结
    网络基础
    问题总结
    Notepad++安装
    Django 使用Form组件完成登录注册
  • 原文地址:https://www.cnblogs.com/Mary-Sue/p/9832256.html
Copyright © 2011-2022 走看看