Pagini recente » Borderou de evaluare (job #437081) | Cod sursa (job #253903)
Cod sursa(job #253903)
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int N, M, t[105], nr, a[105], ord[105], nnr;
char s[1006];
vector <int> v[105];
vector <int> comp[105];
void citire()
{
freopen("episoade.in","r",stdin);
freopen("episoade.out","w",stdout);
int i, j, x, y, n;
scanf("%s",s);
scanf("%d %d",&M,&N);
n = strlen(s);
i = 0;
while (i < n)
{
if (s[i] < '0' || s[i] > '9') i++;
x = s[i] - '0';
i++;
while (s[i] >= '0' && s[i] <= '9')
{
x = x * 10 + s[i] - '0';
i++;
}
ord[++nnr] = x;
t[x] = ++nr;
while (s[i] == '>')
{
i++;
y = s[i] - '0';
i++;
while (s[i] >= '0' && s[i] <= '9')
{
y = y * 10 + s[i] - '0';
i++;
}
ord[++nnr] = y;
v[x].push_back(y);
t[y] = t[x];
x = y;
}
}
for (i = 1; i <= nr; i++)
for (j = 1; j <= N; j++)
if (t[ord[j]] == i) comp[i].push_back(j);
}
int main()
{
citire();
int i, j, n, ok, x;
while (M--)
{
for (i = 1; i <= N; i++) scanf("%d ", &a[i]);
ok = 1;
for (i = 1; i <= N; i++)
{
x = t[ a[i] ];
n = comp[x].size();
for (j = 0; j < n; j++)
if (a[i + j] != comp[x][j])
{
ok = 0;
break;
}
if (!ok) break;
i += n - 1;
}
printf("%d\n",ok);
}
return 0;
}