#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;
}
This entry was posted on October 6, 2009 at 6:11 pm and is filed under ACM (UVa) Algorithm . You can follow any responses to this entry through the RSS 2.0 feed
You can skip to the end and leave a response. Pinging is currently not allowed.