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

1065 单身狗

 

上一篇:PAT甲级-1065 A+B and C (64bit) (20分)


下一篇:挑战程序设计竞赛2.3:Wooden Sticks POJ - 1065