Last active
May 16, 2016 22:22
-
-
Save rep-movsd/b33ddc55bd0f29bd329c4df598f48b42 to your computer and use it in GitHub Desktop.
RuleEngine (CC 2002 REG Semi 1000 pointer)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define vint vector<int> | |
#define vstr vector<string> | |
#define eb emplace_back | |
#define st string | |
#define cstref const string& | |
#define sz(x) int(x.size()) | |
#define beg(x) begin(x) | |
#define all(x) begin(x), end(x) | |
#define var auto | |
#define pbeg(x) &x[0] | |
#define pend(x) (&x[0] + sz(x)) | |
#define LOOP(I, J, K) for(int I = J; I < K; ++I) | |
using namespace std; | |
vstr split(cstref s, st seps=" ") | |
{ | |
vstr ret; | |
for(var ps = pbeg(s), pd = ps, pe = ps + sz(s); ps < pe; ps = pd + 1) | |
{ | |
ret.eb(st(ps, pd = find_first_of(ps, pe, all(seps)))); | |
} | |
return ret; | |
} | |
struct RuleEngine | |
{ | |
int addRule(char c, const string &op, const string &svals) | |
{ | |
int n = 0; | |
auto strvals = split(svals, ","); | |
int vals[] = {stoi(strvals[0]), stoi(strvals[1])}; | |
#define HANDLE_OP(OP) if(op == # OP) LOOP(i, -10, 11) if(i OP vals[0]) ++n; | |
HANDLE_OP(==); | |
HANDLE_OP(!=); | |
HANDLE_OP(<); | |
HANDLE_OP(>=); | |
HANDLE_OP(>); | |
HANDLE_OP(<=); | |
if(op == "B") LOOP(i, -10, 11) if(i >= vals[0] && i <= vals[1]) ++n; | |
} | |
string countSets(vector<string> param0, vector<string> param1) | |
{ | |
param0.insert(end(param0), all(param1)); | |
long long total = 1; | |
for(const var &s:param0) | |
{ | |
auto iVal = s.find_first_not_of("<>!=B", 1); | |
n *= addRule(s[0], s.substr(1, iVal-1), s.substr(iVal) + ",0"); | |
} | |
return to_string(total); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment