zoukankan      html  css  js  c++  java
  • 1065. 单身狗(25)

    “单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱。

    输入格式:

    输入第一行给出一个正整数N(<=50000),是已知夫妻/伴侣的对数;随后N行,每行给出一对夫妻/伴侣——为方便起见,每人对应一个ID号,为5位数字(从00000到99999),ID间以空格分隔;之后给出一个正整数M(<=10000),为参加派对的总人数;随后一行给出这M位客人的ID,以空格分隔。题目保证无人重婚或脚踩两条船。

    输出格式:

    首先第一行输出落单客人的总人数;随后第二行按ID递增顺序列出落单的客人。ID间用1个空格分隔,行的首尾不得有多余空格。

    输入样例:

    3
    11111 22222
    33333 44444
    55555 66666
    7
    55555 44444 10000 88888 22222 11111 23333
    

    输出样例:

    5
    10000 23333 44444 55555 88888
     1 #include<stdio.h>
     2 #include<math.h>
     3 #include<stdlib.h>
     4 
     5 int ans[100001]={0};  
     6 int presented[10001]={0};  //记录出席的标号
     7 int main()
     8 {
     9     int n,m;
    10     int i,j;
    11     int temp1,temp2;
    12     int flag=1,cnt=0;
    13     scanf("%d",&n);
    14     for( i=0; i<n; i++)
    15     {
    16         scanf("%d%d",&temp1,&temp2);
    17         ans[temp1]=temp2;  //夫妻互相标号
    18         ans[temp2]=temp1;
    19     }
    20     scanf("%d",&m);
    21     for( i=0; i<m; i++)
    22         scanf("%d",&presented[i]);
    23     for( i=0; i<m; i++)
    24     {
    25         if( ans[presented[i]]==0) //如果该编号不存在对象,直接置-1
    26             ans[presented[i]]=-1;
    27         else if (ans[presented[i]]==1); //空循环
    28         else if (ans[presented[i]]==-1); //空循环
    29         else{  //如果该编号存在对象,判断出席的人里是否有与他对象编号相同的编号
    30             for( j=i+1; j<m; j++)
    31             {
    32                 if(ans[presented[i]] == presented[j])
    33                 {
    34                     ans[presented[i]]=1;  //如果存在则置1
    35                     ans[presented[j]]=1;
    36                     break;
    37                 }
    38             }
    39             if( ans[presented[i]]!=1) ans[presented[i]]=-1;
    40         }
    41     }
    42     for( i=0; i<100001; i++)
    43     {
    44         if( ans[i]==-1)
    45             cnt++;
    46     }
    47     printf("%d
    ",cnt++);
    48     for(i=0; i<=100000; i++) //输出所有置为-1的编号
    49     {
    50         if( ans[i]==-1 && flag==1)
    51           {
    52              printf("%05d",i);
    53              flag=0;
    54           }
    55           else if( ans[i]==-1 && flag==0)
    56             printf(" %05d",i);
    57     }
    58     return 0;
    59 }
    在这个国度中,必须不停地奔跑,才能使你保持在原地。如果想要寻求突破,就要以两倍现在速度奔跑!
  • 相关阅读:
    如何构建积木式Web应用
    ASP.NET 2.0 异步页面原理浅析 [1] [原]
    HybridDictionary 类
    datagrid自定义
    认识.NET的集合
    织梦 10060
    java.io.FileNotFoundException: E:\temp (拒绝访问。)
    引用与对象实例化
    C#中为DataGrid添加下拉列表框
    C#中使用指针
  • 原文地址:https://www.cnblogs.com/yuxiaoba/p/8533020.html
Copyright © 2011-2022 走看看