Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Validating Roman Numerals Hacker Rank Solution – Queslers

Problem : Validating Roman Numerals Hacker Rank Solution

You are given a string, and you have to validate whether it’s a valid Roman numeral. If it is valid, print True. Otherwise, print False. Try to create a regular expression for a valid Roman numeral.


Input Format :

A single line of input containing a string of Roman characters.

Output Format :

Output a single line containing True or False according to the instructions above.

Constraints :

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


Sample Input :

CDXXI

Sample Output :

True

Validating Roman Numerals Hacker Rank Solution in python 2

import sys
import re
pattern = '^M{0,3}(D?C{0,3}|C(D|M))(L?X{0,3}|X(L|C))(V?I{0,3}|I(V|X))$'

string = sys.stdin.readline().strip()
match = re.search(pattern, string)
if match and string != '':
    print 'True'
else:
    print 'False'

Validating Roman Numerals Hacker Rank Solution in python 3

thousand = 'M{0,3}'
hundred = '(C[MD]|D?C{0,3})'
ten = '(X[CL]|L?X{0,3})'
digit = '(I[VX]|V?I{0,3})'
regex_pattern = r"%s%s%s%s$" % (thousand, hundred, ten, digit)   # Do not delete 'r'

Validating Roman Numerals Hacker Rank Solution in pypy

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re
pattern = '^(?=[MDCLXVI])M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$'
roman = str(raw_input())
if re.search(pattern, roman):
    print 'True'
else:
    print 'False'

Validating Roman Numerals Hacker Rank Solution in pypy 3

# Enter your code here. Read input from STDIN. Print output to STDOUT
import re

ptrn = r'^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$'
s = input().strip()

x = re.match(ptrn,s)
if x:
    print(True)
else:
    print(False)
Validating Roman Numerals Hacker Rank Solution Review:

In our experience, we suggest you solve this Validating Roman Numerals Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

Validating Roman Numerals is available on Hacker Rank for Free, if you are stuck anywhere between compilation, just visit Queslers to get all Hacker Rank Solution

Maximize It! Hacker Rank Solution Conclusion:

I hope this Validating Roman Numerals Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Hacker Rank Problem & Solutions >>

Mini-Max Sum Hacker Rank Solution

String Validators Hacker Rank Solution

Text Alignment Hacker Rank solution

String validators Hacker Rank Solution

Staircase Hacker Rank Solution

Leave a Reply

Your email address will not be published. Required fields are marked *