zoukankan      html  css  js  c++  java
  • Lisp em SCU

    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
    ");
            else
                cout<<"Yes"<<" "<<a[0]<<endl;
        }
        return 0;
    }
  • 相关阅读:
    tomcat加载项目原理解惑
    英语口语大全
    ubuntu中wubi正在下载ubuntu11.04desktopi386.iso
    Strust2获得session和request
    字符串转成对象
    DevExpress控件使用
    DevExpress控件之GridControl控件(控件篇)
    ASP.NET AJAX + JSON 实现对象调用
    WinForm窗体之间交互的一些方法[转]
    barmanager设置
  • 原文地址:https://www.cnblogs.com/nyist-xsk/p/7264851.html
Copyright © 2011-2022 走看看