http://acm.sgu.ru/problem.php?contest=0&problem=406
判断所给的序列是否在数据库的序列中,-号表示排除,例如1,-2,3不在序列1,2,3,4中,因为-2排除了2,简单地判断即可。
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
int main(void) {
int n, m;
scanf ("%d%d", &n, &m);
int seq[10][11];
int i, j;
for (i = 0; i < n; ++i) {
scanf ("%d", seq[i]);
for (j = 1; j <= seq[i][0]; ++j) {
scanf ("%d", seq[i]+j);
}
}
int search[11];
int k, p, q;
bool can;
for (i = 0; i < m; ++i) {
scanf ("%d", search);
for (j = 1; j <= search[0]; ++j) {
scanf ("%d", search+j);
}
int count = 0;
int record[10];
for (k = 0; k < n; ++k) {
can = false;
for (p = 1; p <= search[0]; ++p) {
can = false;
for (q = 1; q <= seq[k][0]; ++q) {
if (abs(search[p]) == seq[k][q]) {
can = true;
break;
}
}
if ((!can && search[p] >= 0) || (can && search[p] < 0)) {
can = false;
break;
}
if (!can && search[p] < 0) {
can = true;
}
}
if (can) {
record[count++] = k;
}
}
printf ("%d\n", count);
for (k = 0; k < count; ++k) {
printf ("%d", seq[record[k]][0]);
for (p = 1; p <= seq[record[k]][0]; ++p) {
printf (" %d", seq[record[k]][p]);
}
printf ("\n");
}
}
return 0;
}