ACM (UVa) : 271


#include <stdio.h>
#include <string.h>

int main ()
{
	long Len, N, I;
	char A [10000];

	while (gets (A)) {

		Len = strlen (A);
		N = 0;

		for (I = Len - 1; I >= 0; I--) {
			
			if (A [I] > 111 && A [I] < 123 )
				N++;

			else if (A [I] == 67 || A [I] == 68 || A [I] == 69 || A [I] == 73) {
				if (N >= 2)
					N--;
				else {
					N = 0;
					break;
				}
			}

			else if (A [I] == 78 ) {
				if (N < 1) {
					N = 0;
					break;
				}
			}
		}

		if (N == 1)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s