Skip to content

Instantly share code, notes, and snippets.

@msramalho
Created October 11, 2018 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msramalho/c927d70e17d21e83e34b9bbd6cbce7cf to your computer and use it in GitHub Desktop.
Save msramalho/c927d70e17d21e83e34b9bbd6cbce7cf to your computer and use it in GitHub Desktop.
There is a bug
#include <bits/stdc++.h>
using namespace std;
#define MK make_pair
#define PB push_back
#define ALL(v) (v).begin() , (v).end()
#define two(n) ( 1 << (n) )
#define contain(Set,i) ( (Set) & two(i) )
#define FOR(i,n) for (int i = 0; i < (n); i++)
#define REP(i, b, e) for (typeof(e) i=b; i!=e; ++i)
#define COST first
#define V1 second.first
#define V2 second.second
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
const int& INF = numeric_limits<int>::max();
#define NONE 0
#define NOT 1
#define OR 2
#define AND 3
struct op {
int val=0, name=0;//name: 0, 1 is not, 2 is or, 3 is and
op *opl, *opr;
op(){}
op(int v){val=v;}
op(op *opll){opl=opll;name=NOT;}
op(op *opll, op *oprr, int nname){opl=opll;opr=oprr;name=nname;}
bool exec(string &bin){
cout<<"operation="<<name<<" val="<<val<<"-"<<opl<<endl;
if (name==NONE) return bool(char(bin[val])-'0');
if (name==NOT) return not opl->exec(bin);
if (name==OR) return opl->exec(bin) or opr->exec(bin);
if (name==AND) return opl->exec(bin) and opr->exec(bin);
return false;
}
};
int main() {
freopen("b.txt", "r", stdin);
int N;cin>>N;
//string tmp = "01";cout<<bool(tmp[0])<<"-"<<bool(tmp[1])<<endl;
vector <op> rules(N);
FOR(i,N){
int f;cin>>f;
cout<<f<<"pars"<<endl;
stack <op> s;
op t,tt; // temp
FOR(j, f){
string c;cin>>c;
cout<<c<<" ";
if (c == "-"){
t = s.top();s.pop();
s.push(op(&t));//insert a not of the previous op
}else if(c=="+"){
t = s.top();s.pop();
tt = s.top();s.pop();
s.push(op(&t,&tt, OR));
}else if(c=="*"){
t = s.top();s.pop();
tt = s.top();s.pop();
s.push(op(&t,&tt, AND));
}else{//this is a number
s.push(op(stoi(c)));
}
cout<<"("<<s.size()<<")";
}
cout<<endl;
rules[i] = s.top();
string bin = "00000";
cout<<"res: " << s.top().exec(bin)<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment