ribbon logo
ribbon contest type Free Academy Experience

Preparing for tech interviews?
Learn from the best instructors in the field.

Try Academy for FREE!


Validating Roman Numerals

Problem Description

You are given N input string, and you have to validate whether they are valid Roman numeral or not.

If it is valid, print "YES". Otherwise, print "NO". Try to create a regular expression for a valid Roman numeral.

Know more about Roman numeral here

Problem Constraints

1 <= N <= 10

The number will be between 1 and 3999 (both included).

Input Format

First line contains an integer N, the number of inputs.

N lines follow, each containing some string.

Output Format

For every string listed, print "YES" if it is a valid roman numeral and "NO" if it is not on separate lines. Do not print the quotes.

Example Input

3
CDXXI
M
IIX

Example Output

YES
YES
NO
Start solving Validating Roman Numerals on Interview Code Editor
Hints
  • Solution Approach
  • Complete Solution

Discussion


Loading...
Click here to start solving coding interview questions