其他分享
首页 > 其他分享> > 1065 单身狗

1065 单身狗

作者:互联网

hash题。。。

#include<iostream>
#include<algorithm>
using namespace std;

int hashtable[100500]= {0};
int c[100500] = {0};
int main() {
    int n,a,b,m;
    cin>>n;
    for(int i = 0; i < n; ++i) {
        scanf("%d%d",&a,&b);
        hashtable[a] = b;
        hashtable[b] = a;
    }
    cin>>m;
    int cnt = m;
    for(int i = 0; i < m; ++i)
        scanf("%d",&c[i]);
    for(int i = 0; i < m; ++i) {
        if(c[i] != 0x3fffffff) {
            for(int j = i+1; j < m; ++j) {
                if(hashtable[c[i]] == c[j]) {
                    c[i] = 0x3fffffff;
                    c[j] = 0x3fffffff;
                    cnt -= 2;
                    break;
                }
            }
        }
    }
    cout<<cnt<<endl;
    sort(c,c+m);//递增排序 
    for(int i = 0; i < cnt; ++i) {
        if(i > 0) printf(" ");
        printf("%05d",c[i]);
    }
    return 0;
}

 

标签:cnt,0x3fffffff,int,1065,++,hashtable,单身,printf
来源: https://www.cnblogs.com/keep23456/p/12354519.html