Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- using namespace std;
- bool hasHappened(string e, string events[], int a, int& found) {
- for ( ; a >= 0; a--) {
- if (e == events[a]) {
- found = a;
- return true;
- }
- }
- return false;
- }
- bool consistent(int sEvents, int events, string S[], string E[], int dreamed, int& found) {
- for (int i = 0; i < sEvents; i++) {
- string ev = S[i];
- bool invert = false;
- if (ev[0] == '!') {
- invert = true;
- ev.erase(0, 1);
- }
- bool h = hasHappened(ev, E, events-dreamed, found);
- if ((!h && !invert) || (h && invert))
- return false;
- }
- return true;
- }
- int main (int argc, char * const argv[]) {
- ios::sync_with_stdio(false);
- cin.tie(NULL);
- int a;
- char type;
- cin >> a;
- string event[a];
- int eventC = -1;
- for ( ; a > 0; a--) {
- cin >> type;
- if (type == 'E') {
- eventC++;
- cin >> event[eventC];
- }
- else if (type == 'S') {
- int b = 0;
- cin >> b;
- string events[b];
- for (int i = 0; i < b; i++)
- cin >> events[i];
- int found;
- if (consistent(b, eventC, events, event, 0, found)) {
- printf("Yes\n");
- }
- else {
- bool foundDream = false;
- for (int i = 1; i <= eventC + 1; i++) {
- if (i > eventC-found) {
- if (consistent(b, eventC, events, event, i, found)) {
- printf("%d Just A Dream\n", i);
- foundDream = true;
- break;
- }
- }
- }
- if (!foundDream) {
- printf("Plot Error\n");
- }
- }
- }
- else {
- int c = 0;
- cin >> c;
- eventC -= c;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement