[Swust OJ 632]--set operation (Set container)

Source: Internet
Author: User

Title Link: http://acm.swust.edu.cn/problem/632/

Time limit (ms): $ Memory Limit (KB): 65535 The Description collection is an operation that specifies a new collection with a given set. Set A and B are sets, their corresponding complementary sets are defined as follows:
A∪B={X|X∈A∨X∈B}
A∩B={X|X∈A∧X∈B}
A–b={x|x∈a∧x does not belong to B}
SA ={x|x∈ (a∪b) ∧x does not belong to A}
SB ={x|x∈ (a∪b) ∧x does not belong to B}
Input inputs may have up to one row of data
The first line enters the number of elements of set a M1 (m1>=0), and the next line enters the elements of set a
The third line enters the number of elements in set B M2 (m2>=0), and the last line enters the elements of collection B
Output outputs total 7 rows
The first 2 rows output sets A, B, and then 5 rows to output the set A, B and (A∪b), intersection (A∩B), Difference (a–b), and complement respectively.
Sample Input
41 3 2 10

Sample Output
A={1, 2, 3}b={}aub={1, 2, 3}anb={}a-b={1, 2, 3}sa={}sb={1, 2, 3}

Hint in order to uniquely determine the output, the elements of the set output the problem-solving idea in ascending direction: Noticing the ascending output, combined with the characteristics of set operation, directly using Set container water over orz~~~
1#include <iostream>2#include <Set>3#include <string>4#include <algorithm>5#include <iterator>6 using namespacestd;7 8 Set<int>A, B, C, D, E, F, G;9 intN, m, X;Ten  One voidinit () { A a.clear (); B.clear (); - c.clear (); D.clear (); - e.clear (); F.clear (); G.clear (); the } -  - voidOrder (stringStrSet<int>s) { -cout << str <<"={"; +      for(Set<int>::iterator it = S.begin (); It! = S.end (); it++){ -         if(It = = S.begin ()) cout << *it; +         Elsecout <<", "<< *it; A     } atcout <<"}"<<Endl; - } - intMain () { -      while(Cin >>N) { - init (); -          for(inti =0; I < n; i++){ inCIN >>x; - A.insert (x); to         } +CIN >>m; -          for(inti =0; I < m; i++){ theCIN >>x; * B.insert (x); $         }Panax NotoginsengSet_union (A.begin (), A.end (), B.begin (), B.end (), insert_iterator<Set<int> > (c, C.begin ()));//and -Set_intersection (A.begin (), A.end (), B.begin (), B.end (), insert_iterator<Set<int> > (d, D.begin ()));//Pay theSet_difference (A.begin (), A.end (), B.begin (), B.end (), insert_iterator<Set<int> > (E, E.begin ()));//Poor +Set_difference (C.begin (), C.end (), A.begin (), A.end (), insert_iterator<Set<int> >(F, F.begin ())); ASet_difference (C.begin (), C.end (), B.begin (), B.end (), insert_iterator<Set<int> >(g, G.begin ())); theOrder ("A", a); +Order ("B", b); -Order ("AuB", c); $Order ("AnB", d); $Order (" A-B", e); -Order ("SA", f); -Order ("SB", g); the     } -     return 0;Wuyi}
View Code

[Swust OJ 632]--set operation (Set container)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.