SCU4490 Lisp em(string和map容器的应用)

来源:互联网 发布:金融分析软件 编辑:程序博客网 时间:2024/05/16 14:27

题目:



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 nilnil 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

20x233333 0x123456 0xabcdef1 0xffffff nil0x999999 0x332232 0xffffff nil0x233333 0x123456 0xabcdef1 0xffffff nil0x987654 0xafafaf 0xfffcccc 0xaaface nil

Sample Output

Yes 0xffffffNo

Author

qw4990

思路;

这就没什么思路了,一看代码肯定懂了,注意细节就好,存一存代码~

代码:

#include <stdio.h>#include <stdlib.h>#include <math.h>#include <iostream>#include <cstring>#include <vector>#include <map>#include <string>#define N 500#define LL long long#define mem(a,b) memset(a,b,sizeof(a))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;}

0 0
原创粉丝点击