PAT甲题题解-1121. Damn Single (25)-水题

博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~
http://www.cnblogs.com/chenxiwenruo/p/6789787.html
特别不喜欢那些随便转载别人的原创文章又不给出链接的
所以不准偷偷复制博主的博客噢~~

 

给出n个couple和m个宾客
如果宾客没有couple或者couple没来,则被认为lonely
问你有多少个lonely的宾客,并且按照id的升序输出

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=100000+5;
int couple[maxn];
int vis[maxn];

int main()
{
    int n,m;
    int a,b;
    memset(couple,-1,sizeof(couple));
    memset(vis,0,sizeof(vis));
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d %d",&a,&b);
        couple[a]=b;
        couple[b]=a;
    }
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        scanf("%d",&a);
        vis[a]=1;
    }
    int ans[maxn];
    int cnt=0;
    for(int i=0;i<maxn;i++){
        if(vis[i]){
            int cp=couple[i];
            if(cp==-1 || vis[cp]==0){
                ans[cnt++]=i;
            }
        }
    }
    printf("%d\n",cnt);
    if(cnt)
        printf("%05d",ans[0]);
    for(int i=1;i<cnt;i++)
        printf(" %05d",ans[i]);
    return 0;
}
View Code

 

posted @ 2017-04-30 16:46  辰曦~文若  阅读(420)  评论(0编辑  收藏  举报