码迷,mamicode.com
首页 > 其他好文 > 详细

PAT 甲级 1121 Damn Single

时间:2017-06-24 19:50:13      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:ret   out   first   single   style   ace   ring   ++   main   

 1 #include <iostream>
 2 #include <string.h>
 3 #include <algorithm>
 4 #include <cstdio>
 5 
 6 int a[100000], b[100000], c[100000];
 7 int panduan=0;
 8 int ff=0;
 9 using namespace std;
10 
11 void bijiao(int gps, int x, int n)
12 {
13     for (int i=gps+1; i<n; i++)
14     {
15         if (a[b[gps]]==b[i])
16         {
17             b[gps] = 0;
18             b[i] = 0;
19         }
20     }
21 }
22 void qiushu(int n)
23 {
24     for (int i=0; i<n; i++)
25     {
26         if (b[i]==0)
27         {
28             ff++;
29         }
30     }
31 }
32 void shuchu(int n)
33 {
34     qiushu(n);
35     //cout <<ff/2 <<endl;
36     cout <<n-ff <<endl;
37     sort (b, b+n/*,cmp*/);
38     int first = 0;
39     for (int i=0; i<n; i++)
40     {
41         if (b[i])
42         {
43             if (first)
44             {
45             cout <<" ";
46             }
47             printf("%05d",b[i]);
48             first = 1;
49         }
50     }
51 
52 }
53 int main()
54 {
55     int N;
56     cin >>N;
57     for (int i=0; i<N; i++)
58     {
59         int x;
60         cin >>x;
61         cin >>a[x];
62         a[a[x]] = x;
63     }
64     int M;
65     cin >>M;
66     for (int i=0; i<M; i++)
67     {
68         cin >>b[i];
69     }
70    
71     for (int i=0; i<M; i++)
72     {
73         bijiao(i, b[i], M);
74     }
75     
76     shuchu(M);
77 
78     return 0;
79 }

 

PAT 甲级 1121 Damn Single

标签:ret   out   first   single   style   ace   ring   ++   main   

原文地址:http://www.cnblogs.com/GrayArchimage/p/7074141.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!