β Why does this Roman numeral to denary converter not work?
I can see that the problem is if an X is inputed after a CM, it makes it 1000 rather than 900. https://paste.mod.gg/wehmvqpimjrw/0 https://leetcode.com/problems/roman-to-integer/
BlazeBin - wehmvqpimjrw
A tool for sharing your source code with the world!
LeetCode
Roman to Integer - LeetCode
Can you solve this real interview question? Roman to Integer - Roman numerals are represented by seven different symbols:Β I, V, X, L, C, D and M.
Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
For example,Β 2 is written as IIΒ in Roman numeral, just two...
20 Replies
Rather than 910 you mean?
no i meant it outputs 1010 rather than 910
so cm is registered as 1000
when it shouold be 900
But cm on its own is correct?
It's only an issue when it's cmx?
yes
I'm still reading your code and haven't quite found the bug yet, but I can link my implementation if you wanted to see it
yes please
I've been trying to figure it out for like 4 hours lmao
finally given up
thanks
you definitely had a lot more efficient approach
im still frustrated I cant figure out the bug tho
I mean... the most efficient code is just to have a single switch for every case π
there are only ~4000 numbers that roman numerals can represent
but I felt too dirty having that large of a switch for such a stupid thing... so I didn't do it in my code
fair enough
did you figure out the bug/
I believe you are missing quite a few cases in your code
in my mind you have a bit of a fundamental logic flaw. you shouldn't have both forward looking and reverse looking logic
pick one and stick with it
but probably one thing that was tripping you up was this:
else if (i > 0)
why do you have an "else" there?
forward
and back
are independent variables. both should be "if" checks not one "if" and one "if else"thanks
that fixed it
Surely this isn't true
Pretty sure there's a sign for 5k and 10k
it wasnt even my idea lol, someone in this server told me to use it - @Pobiega
the standard roman numerals only go to 3999
I also told you this was a very fragile approach to Roman numerals :p
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View