joj1011

 1011: If only I had a Venn diagram


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s524288K39901595Standard

The symmetric difference of two sets is the set of elements belonging to one but not both of the two sets. For example, if we have two sets A = {1,2,3,4,5} and B = {3,4,5,6,7,8}, then the symmetric difference of A and B is the set {1,2,6,7,8}.

Given two sets of positive integers, display their symmetric difference.

Input

 

A positive integer will denote the number of cases. Both sets will be input from a single line. A zero (0) marks the end of each set. There will be no more than 20 numbers in each set, and no number within a set will be repeated. Each number in a set is a positive integer less than 65535.

Output

 

The set of integers making up the symmetric difference of the two sets. The numbers within a set may be sorted from smaller to bigger.

Sample Input

3
1 2 3 4 5 0 3 4 5 6 7 8 0
1 2 3 0 1 2 3 0
129 34 5 6 7 0 129 0

Sample Output

{1,2,6,7,8}
{}
{5,6,7,34}

 


This problem is used for contest: 50 


Submit / Problem List / Status / Discuss

 
将全部数据存入一个数组,对数组进行快排。用一个类似于索引数组的东西将不重复的数输出。
 1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 int cmp(const void *a, const void *b)
6 {
7 return *(int *)a - *(int *)b;
8 }
9
10 void output(int a[], int t)
11 {
12 int b[50];
13 memset(b, 0, sizeof(b));
14 int i;
15
16 for (i=0; i<t-1; i++)
17 {
18 if (a[i] == a[i+1])
19 {
20 b[i] = b[i+1] = 1;
21 }
22 }
23 int flag = 1;
24 printf("{");
25 for (i=0; i<t; i++)
26 {
27 if (flag && 0 == b[i])
28 {
29 flag = 0;
30 printf("%d", a[i]);
31 }
32 else
33 {
34 if (0 == b[i])
35 {
36 printf(",%d", a[i]);
37 }
38 }
39 }
40 printf("}\n");
41
42 }
43
44 int main(void)
45 {
46 int sample, val;
47 int a[50];
48
49 freopen("in.txt", "r", stdin);
50
51 while (scanf("%d", &sample) == 1)
52 {
53 for (int i=0; i<sample; i++)
54 {
55 int j = 0;
56 while(scanf("%d", &val), val)
57 {
58 a[j++] = val;
59 }
60
61 while (scanf("%d", &val), val)
62 {
63 a[j++] = val;
64 }
65
66 qsort(a, j, sizeof(int), cmp);
67
68 output(a, j);
69 }
70 }
71
72 return 0;
73 }

转载于:https://www.cnblogs.com/RootJie/archive/2012/01/27/2330115.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值