4490: Lisp em

Time Limit: 1000 MS    Memory Limit: 131072 K 


Description

There are two lists and they may be intersected with each other. You must judge if they are intersected and find the first node they have in common.

Input

The first line is the number of cases. Each case consists of two lists. Each list consists of multiple nodes. Each node is represented by its address in memory. So, a list may look like this: 0x233333 0x123456 0xabcdef1 0xffffff nil nil is the end of the list. All lists have no cycle. The length of list is not larger than 4e5. List can't be empty. Warn: huge input.

Output

"No" if they are not intersected. "Yes Address", if they are intersected, print "Yes" and the address of their first common node.

Sample Input

2 0x233333 0x123456 0xabcdef1 0xffffff nil 0x999999 0x332232 0xffffff nil 0x233333 0x123456 0xabcdef1 0xffffff nil 0x987654 0xafafaf 0xfffcccc 0xaaface nil

Sample Output

Yes 0xffffff No

Author

qw4990

题目大意:给出两对字符串,问你两串是否存在相交的地方,如果存在,输出第一个相交的字符串。

思路:题目很简单,用一个stl里的map函数就行了,比赛时没有清空,一直wa,清空就过了。。。。。

代码:

#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll unsigned long long
#define inf 0x3f3f3f3
#define esp 1e-8
#define bug {printf("mmp\n");}
#define mm(a,b) memset(a,b,sizeof(a))
#define T() int test,q=1;scanf("%d",&test); while(test--)
const int maxn=2e6+100;
const double pi=acos(-1.0);
const int N=5e4+10;
const int mod=1e9+7;

char s2[N][10];
map<string,bool>s1;
int main()
{
    T()
    {
        s1.clear();
        int l1=0,l2=0;
        while(1)
        {
            string ss;
            cin>>ss;
            s1[ss]=true;
            if(ss=="nil")
                break;
        }
        while(1)
        {
            scanf("%s",s2[l2]);
            if(strcmp(s2[l2],"nil")==0)
                break;
            l2++;
        }
        int id=0;
        for(int i=0; i<l2; i++)
        {
            if(s1[s2[i]]==true)
            {
                id=i;
                break;
            }
        }
        if(id)
        {
            printf("Yes %s\n",s2[id]);
        }
        else
            printf("No\n");
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值