Sunday, June 7, 2015

UVa 271 - Simply Syntax

// UVa 271 - Simply Syntax

#include <iostream>
#include <string>
using namespace std;

string l;
int i;

void advance() {
	if (i >= l.length()) {
		i++;
		return;
	}
	if (l[i] == 'N') {
		i++;
		advance();
	} else if (l[i] == 'C' || l[i] == 'D' || l[i] == 'E' || l[i] == 'I') {
		i++;
		advance();
		advance();
	} else if (l[i] >= 'p' && l[i] <= 'z') {
		i++;
	}
}

int main() {
	while (getline(cin, l) && l.length() > 0) {
		i = 0;
		advance();
		if (i == l.length())
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
}

No comments:

Post a Comment