Pagini recente » Cod sursa (job #2326051) | Cod sursa (job #190195) | Cod sursa (job #2254065) | Cod sursa (job #2894702) | Cod sursa (job #253711)
Cod sursa(job #253711)
#include <algorithm>
#include <stdio.h>
#include <vector>
#define MAX 1024
#define pb push_back
using namespace std;
int n, testCases, parGs = 0, nrMult = 1;
char strCond[MAX];
int apElem[MAX], tata[MAX];
short saNuInterc[128][128];
vector <int> elemMult[128];
void prelucreazaCP(char s[], int st)
{
}
bool valideazaCP(vector <int> pnm)
{
return 0;
}
void prelucreaza50(char s[])
{
int lung = strlen(s), nrElem = 0;
for (int i = 0, x = 1; i < lung; i = x + 1)
{
if (s[i] != '#' && s[i] != '>')
nrElem++;
for (x = i; '0' <= s[x] && s[x] <= '9' && x < lung; x++)
apElem[nrElem] = apElem[nrElem] * 10 + (s[x] - '0');
}
int acElem = 0, acMult = 1;
int vctAparut[MAX];
memset(vctAparut, 0, sizeof(vctAparut));
for (int x = 0; x < lung; x++)
{
if (s[x] == '#' || s[x] == '>')
{
elemMult[acMult].pb(apElem[acElem + 1]);
acElem++;
}
vctAparut[apElem[acElem]] = 1;
if (s[x] == '>')
tata[apElem[acElem + 1]] = apElem[acElem];
if (s[x] == '#')
acMult++;
}
elemMult[acMult].pb(apElem[n]);
}
bool valideaza50(vector <int> pnm)
{
bool vctAparut[MAX];
memset(vctAparut, 0, sizeof(vctAparut));
vctAparut[0] = 1;
for (int x = 0; x < pnm.size(); x++)
{
vctAparut[pnm[x]] = 1;
if (!vctAparut[tata[pnm[x]]])
return 0;
int nuAmVoie = -1;
for (int i = 1; i <= nrMult; i++)
{
int gs = 0;
for (int j = 0; j < elemMult[i].size(); j++)
if (elemMult[i][j] == pnm[x])
gs = 1;
if (gs)
continue;
for (int j = 1; j < elemMult[i].size(); j++)
if (vctAparut[elemMult[i][j]] != vctAparut[elemMult[i][j - 1]])
return 0;
}
}
return 1;
}
int main()
{
freopen("episoade.in", "r", stdin);
freopen("episoade.out", "w", stdout);
fgets(strCond, MAX, stdin);
for (int i = 1; i <= strlen(strCond); i++)
{
if (strCond[i] == ')')
parGs = 1;
if (strCond[i] == '#')
nrMult++;
}
scanf("%d %d\n", &testCases, &n);
if (parGs)
prelucreazaCP(strCond, 0);
else prelucreaza50(strCond);
for (; testCases; testCases--)
{
vector <int> vctPnm;
for (int i = 0; i < n; i++)
{
int elem;
scanf("%d", &elem);
vctPnm.pb(elem);
}
if (parGs)
printf("%d\n", valideazaCP(vctPnm));
else printf("%d\n", valideaza50(vctPnm));
}
fclose(stdin);
fclose(stdout);
return 0;
}