{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

1071 -...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<iostream> #include<cstring> #include<cstdio> #include<cstdlib> using namespace std; enum { SIZ = 104, AND = ')', OR = '>', }; struct Node { bool rev; int type; int v, l, r; Node *link; }; char pic[SIZ][SIZ]; Node tree[SIZ]; int num, x, y, row; Node * pnt[SIZ]; // 0 means not used, for A, B, C, D... int move[4][2] = { {-1, 0}, {0, 1}, {1, 0}, {0, -1} }; bool valid(int r, int c){ return (r>=0)&&(r<row) &&(c>=0&&c<100); } int calc(int p){ if (tree[p].v != -1){ return tree[p].v; } int a = calc(tree[p].l); int b = calc(tree[p].r); if (tree[p].type == AND){ a = (a&&b); } else if (tree[p].type == OR){ a = (a||b); } if (tree[p].rev) a = 1 - a; tree[p].v = a; return tree[p].v; } bool match(char ch, int d){ if (ch <= 32) return false; if (d%2==0 && ch=='-') return false; if (d%2==1 && ch=='|') return false; return true; }
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
void build_tree(int r, int c){ Node &o = tree[num]; o.rev = false; o.v = o.l = o.r = -1; o.link = 0; o.type = 0; int d = 3; if (num == 0){ for (d=0; d<4; ++d){ if (!valid(r+move[d][0], c+move[d][1])) continue; char ch = pic[r+move[d][0]][c+move[d][1]]; if (ch > 32) break; } } ++num; do { r += move[d][0]; c += move[d][1]; switch(pic[r][c]){ case ')': o.type = AND; break; case '>': o.type = OR; break; case 'o': o.rev = !o.rev; break; case '+': { int od = (d+3)%4; for (d=(d+1)%4; d!=od; d=(d+2)%4){ int nx = r + move[d][0];
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern