人见人爱A-B
#include <iostream> #include <cstdio> #include <set> #include <algorithm> using namespace std; int main() { int n, m, p[110], q[110], r[110]; while(scanf("%d %d", &n, &m) && (n != 0 || m != 0)) { set<int> a, b, c; for(int i = 0; i < n; ++ i) { scanf("%d", &p[i]); a.insert(p[i]); } for(int i = 0; i < m; ++ i) { scanf("%d", &q[i]); b.insert(q[i]); } int count = 0; for(int i = 0; i < n; ++ i) { if(b.find(p[i]) == b.end()) { c.insert(p[i]); count ++; } } if(count == 0) cout << "NULL"; else { for(set<int>::iterator it = c.begin(); it != c.end(); ++ it) { cout << *it << " "; } } cout << endl; } return 0; }
注意: 每次都要清空集合!!!