1278: Simply Subsets

 1278: Simply Subsets


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K942132Standard

After graduating from the University of Notre Dame, you obtained a job at Top Shelf Software, Inc., as an entry-level computer engineer. On the first day, your manager sits down with you and tasks you with the following job: ``We want to see how well you understand computer programming and the abstract science behind it. As an evaluation for all of our new hires, we require them to write a program to determine the relationship between pairs of sets. I'm quite sure that you'll do well; my confidence is high. Here's a list of requirements for what the program should do. Good luck.''

Input

Your program should accept an even number of lines of text. Each pair of lines will represent two sets; the first line represents set A, the second line represents set B. Each line of text (set) will be a list of distinct integers.

Output

After each pair of lines has been read in, the sets should be compared and one of the following responses should be output:

  • A is a proper subset of B
  • B is a proper subset of A
  • A equals B
  • A and B are disjoint
  • I'm confused!

Sample Input

 

55 27
55 27
9 24 1995
9 24
1 2 3
1 2 3 4
1 2 3
4 5 6
1 2
2 3

Sample Output

 

A equals B
B is a proper subset of A
A is a proper subset of B
A and B are disjoint
I'm confused!

 

 


This problem is used for contest: 117 

 

#include<iostream>
#include<set>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main()
{
    string str;int n;
    while(getline(cin,str))
    {
        set< int > a,b;
        for(istringstream sin(str);sin>>n;) a.insert(n);
        str.clear();
        getline(cin,str);
        for(istringstream sin(str);sin>>n;) b.insert(n);
        if(a==b) {printf("A equals B/n");continue;}
        //q为a,b的并集
        set< int > q;
        set_union(a.begin(),a.end(),b.begin(),b.end(),insert_iterator< set < int > >(q,q.begin()));
        //p为a,b的交集
        set< int > p;
        set_intersection(a.begin(),a.end(),b.begin(),b.end(),insert_iterator< set < int > >(p,p.begin()));
        //v为a,b的差集
        set< int > v;
        set_difference(a.begin(),a.end(),b.begin(),b.end(),insert_iterator< set < int > >(v,v.begin()));
        //u为a,b的环和
        set< int > u;
        set_symmetric_difference(a.begin(),a.end(),b.begin(),b.end(),insert_iterator< set < int > >(u,u.begin()));
        //..........
        if(q==b) {printf("A is a proper subset of B/n");continue;}
        if(q==a) {printf("B is a proper subset of A/n");continue;}
        if(p.size()==0) {printf("A and B are disjoint/n");continue;}
        printf("I'm confused!/n");
    }
    return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值