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;
}

猜你喜欢

转载自blog.csdn.net/lee371042/article/details/88879822
EM
今日推荐