Pagini recente » Cod sursa (job #1172937) | Cod sursa (job #952227) | Cod sursa (job #2414710) | Cod sursa (job #2535559) | Cod sursa (job #961315)
Cod sursa(job #961315)
#include <algorithm>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
ifstream fin("episoade.in");
ofstream fout("episoade.out");
const int nmax= 100;
string s;
int p[nmax+1];
struct str{
int x, y;
str(int _x, int _y){
x= _x; y= _y;
}
};
struct str_cmp{
bool operator()(str x, str y){
return x.x<y.x;
}
};
int ind;
bool sol;
str comp(int pr){
if (pr==0){
vector <str> v;
v.push_back(comp(1));
while (s[ind]=='#'){
++ind;
v.push_back(comp(1));
}
sort(v.begin(), v.end(), str_cmp());
for (int i= 1; i<(int)v.size(); ++i){
if (v[i-1].y+1!=v[i].x){
sol= 0;
}
}
return str(v[0].x, v[v.size()-1].y);
}else if (pr==1){
str l_op= comp(2);
while (s[ind]=='>'){
++ind;
str r_op= comp(2);
if (l_op.y+1!=r_op.x){
sol= 0;
}
l_op.y= r_op.y;
}
return l_op;
}else{
if (s[ind]=='('){
++ind;
str aux= comp(0);
++ind;
return aux;
}else{
int x= 0;
while (s[ind]>='0'&& s[ind]<='9'){
x= x*10+s[ind]-'0';
++ind;
}
return str(p[x], p[x]);
}
}
};
int main(){
int nt, n;
fin>>s>>nt>>n;
for (int ct= 1; ct<=nt; ++ct){
for (int i= 1; i<=n; ++i){
int x;
fin>>x;
p[x]= i;
}
ind= 0; sol= 1;
comp(0);
fout<<sol<<"\n";
}
return 0;
}