Example #1
0
int main() {
    map<string, pair<int, int> > var;
    stack<Bitset> val;
    char buf[80], *p;
    int n, x, y;

    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%s%d%d", buf, &x, &y);
        var[buf] = make_pair(x, y + 1);
    }

    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%s", buf);
        x = strtol(buf, &p, 10);
        if (*p == '\0') {
            val.push(range(x, x + 1));
        } else if (strchr("+-*/", buf[0]) == NULL) {
            pair<int, int> snd = var[buf];
            val.push(range(snd.first, snd.second));
        } else {
            Bitset rhs = val.top();
            val.pop();
            Bitset lhs = val.top();
            val.pop();
            if (buf[0] == '/' && rhs[0]) {
                puts("error");
                return 0;
            } else {
                Bitset ret;
                for (int i = 0; i < (int)lhs.size(); ++i) {
                    if (!lhs[i]) {
                        continue;
                    }
                    for (int j = 0; j < (int)rhs.size(); ++j) {
                        if (!rhs[j]) {
                            continue;
                        }
                        ret.set(eval(i, j, buf[0]));
                    }
                }
                val.push(ret);
            }
        }
    }
    puts("correct");
    return 0;
}
Example #2
0
TEST(Bitset, set)
{
  Bitset<2> bs;
  ASSERT_EQ(bs.size(), 2);
  EXPECT_FALSE(bs[0]);
  EXPECT_FALSE(bs[1]);

  bs.set(0, true);
  EXPECT_TRUE(bs[0]);

  bs.set(0, false);
  EXPECT_FALSE(bs[0]);

  bs.set(1, true);
  EXPECT_TRUE(bs[1]);

  Bitset<82> bs2;
  ASSERT_EQ(bs2.size(), 82);
  EXPECT_FALSE(bs2[70]);
  bs2.set(70, true);
  EXPECT_TRUE(bs2[70]);
}
Example #3
0
TEST(Bitset, size)
{
  Bitset<4> bs;
  EXPECT_EQ(bs.size(), 4);
}