| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1176 人关注过本帖
标题:一道ACM问题 请高手指教 谢谢
只看楼主 加入收藏
jackylin
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-9-5
收藏
 问题点数:0 回复次数:10 
一道ACM问题 请高手指教 谢谢
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}
搜索更多相关主题的帖子: 指教 ACM 
2008-09-05 15:47
中学者
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:20
帖 子:3554
专家分:80
注 册:2007-9-14
收藏
得分:0 
开个数组筛选-,-

樱花大战,  有爱.
2008-09-05 15:59
jackylin
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-9-5
收藏
得分:0 
能具体说下思路么?本人是初学者谢谢
2008-09-05 16:03
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1029
专家分:177
注 册:2007-5-10
收藏
得分:0 
好多做法。
把两个集合一起读到一个数组里,排序,然后遍历,如果一个元素不等于它前面的也不等于它后面的就输出。
2008-09-05 16:11
jackylin
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-9-5
收藏
得分:0 
回复 4# leeco 的帖子
那怎么样输出三个呢?
2008-09-05 16:16
jackylin
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-9-5
收藏
得分:0 
有没有高人附一个完整代码?小弟在此等候
2008-09-05 17:35
中学者
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:20
帖 子:3554
专家分:80
注 册:2007-9-14
收藏
得分:0 
#include<cstdio>
#include<algorithm>
int hash[65536];
int main()
{
    int n,max_;
    scanf("%d",&n);
    for(int i=0;max_=-1&&i<n;++i)
    {  
        int v;
        memset(hash,0,sizeof(hash));
        for(int j=0;j<2;++j)
        while(scanf("%d",&v),v!=0)
        {
          if(!hash[v]) hash[v]=1;
          else hash[v]=0;
          max_=max_<v?v:max_;
        }
        putchar('{');
        for(int i=1;i<=max_;++i) if(hash[i]) printf("%d ",i);
        putchar('}');putchar('\n');
    }
    return 0;
}

樱花大战,  有爱.
2008-09-05 18:22
jackylin
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-9-5
收藏
得分:0 
回复 7# 中学者 的帖子
谢谢你 虽然看不太懂
2008-09-05 19:12
hoodlum1980
Rank: 2
来 自:浙江大学
等 级:论坛游民
威 望:2
帖 子:289
专家分:23
注 册:2008-2-24
收藏
得分:0 
[bo][un]中学者[/un] 在 2008-9-5 18:22 的发言:[/bo]

#include
#include
int hash[65536];
int main()
{
    int n,max_;
    scanf("%d",&n);
    for(int i=0;max_=-1&&i


这已经不叫hash了,为了几十个数,申请几十万字节的空间,相当浪费。。。
2008-09-06 12:00
jackylin
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-9-5
收藏
得分:0 
那你觉得应该怎么样做呢?
2008-09-07 12:41
快速回复:一道ACM问题 请高手指教 谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011989 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved