Pagini recente » Rating Verniceanu Darian (darian4444) | Cod sursa (job #3290355) | Cod sursa (job #3204689) | Cod sursa (job #2293885) | Cod sursa (job #2025690)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#define per pair<int,int>
#define fi first
#define se second
using namespace std;
ifstream si("episoade.in");
ofstream so("episoade.out");
int ok,poz,x,n,a[105];
char s[1005];
inline per eval(int l)
{
if(l==0)
{
vector<per>v;
v.push_back(eval(1));
while(s[poz]=='#')
{
++poz;
v.push_back(eval(1));
}
sort(v.begin(),v.end());
per x;
x=v[0];
for(int i=1;i<v.size();++i)
{
if(v[i-1].se+1!=v[i].fi)
ok=0;
else
x.se=v[i].se;
}
return x;
}
if(l==1)
{
per x,y;
x=eval(2);
while(s[poz]=='>')
{
++poz;
y=eval(2);
if(x.se+1!=y.fi)
ok=0;
x.se=y.se;
}
return x;
}
if(s[poz]=='(')
{
++poz;
per x=eval(0);
++poz;
return x;
}
int x=0;
while(s[poz]>='0'&&s[poz]<='9')
x=x*10+s[poz]-'0',++poz;
return make_pair(a[x],a[x]);
}
int main()
{
int t;
si>>s>>t>>n;
while(t--)
{
for(int i=1;i<=n;++i)
{
si>>x;
a[x]=i;
}
poz=0;
ok=1;
eval(0);
so<<ok<<'\n';
}
return 0;
}