• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[Easy/Tough] Roman Numerals

 
Author
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a program that converts Roman numerals to Arabic and reverse.
Values:
I = 1 (one)
V = 5 (five)
X = 10 (ten)
L = 50 (fifty)
C = 100 (one hundred)
D = 500 (five hundred)
M = 1000 (one thousand)
Examples:
30 is written as XXX but 15 is not written as VVV
40 is written as XL but 45 is not written as VL
9 is written as IX but 49 is not written as IL and 99 is not written as IC
243 is written as CCXLIII
1510 is written as MDX
1999 is written as MCMXCIX
4,9,40,90,400,900 == IV,IX,XL,XC,CC,CM respectively
Rules:
1) No googling for any more rules or hints.
PS:
If the above is just plain boring, then you can solve this quiz or read about the 1999 problem
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's my lash at it.
 
Ranch Hand
Posts: 1376
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's my shot at it:

This will throw an exception if the Roman numeral is incorrect; it doesn't do any nice error checking like Michael's, but it's short and simple.
Joe
 
Jignesh Malavia
Author
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup!
You both get an A+ :-)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic