Lisp em SCU - 4490 (强大的map用法)

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

#include <map>
#include <math.h>
#include <string>
#include <vector>
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std; string s;
map<string,int>mp;
vector<string>a; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
s.clear();
a.clear();
mp.clear();
while(cin>>s&&s!="nil")
mp[s]=1;
while(cin>>s&&s!="nil")
if(mp[s]==1)
a.push_back(s);
if(a.size()==0)
printf("No\n");
else
cout<<"Yes"<<" "<<a[0]<<endl;
}
return 0;
}
上一篇:Android 自定义Dialog工具类


下一篇:IIS 更新EXE文件