Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=437
First, we introduce the 4 functions related to the set operation in the <algorithm> header file:
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
It is obvious that the relationship between the two sets is judged by the intersection.
How to use:
Set_intersection (A, a + N, b, B + M, V.begin ());
Here V is a dynamic array, which is used to save the result of the intersection operation. (other functions are used in a similar way)
The return value of the function minus V.begin () is the size of the collection.
Complete code:
01./*0.016s*/02.
#include <bits/stdc++.h> 04.using namespace std;
06.int a[100], b[100];
07.vector<int> V (100);///initialization space is required 08. 09.int Main () 10.
{one. int n, M, CNT, diff;
Char ch; while (~SCANF ("%d%c", &a[0), &ch) 14. {for (n = 1; ch!= ++n) 16.
scanf ("%d%c", &a[n], &ch);
CNT = scanf ("%d%c", &b[0], &ch); for (m = 1; ch!= && cnt = 2; ++m) 19.
CNT = scanf ("%d%c", &b[m], &ch);
Sort (A, a + N);
Sort (b, B + m);
diff = Set_intersection (A, a + N, b, B + M, V.begin ())-V.begin (); if (diff = min (n, m)) 24.
{. if (n < m) puts ("A is a proper subset of B");
/else if (n > M) puts ("B is a proper subset of a");
/else puts ("A equals B"); 28.} 29.
else if (diff) puts ("I ' m confused!");/else puts ("A and B are disjoint"); 31.} 32.
return 0;
.}