diff options
author | Joursoir <chat@joursoir.net> | 2021-02-04 16:56:40 +0000 |
---|---|---|
committer | Joursoir <chat@joursoir.net> | 2021-02-04 16:56:40 +0000 |
commit | 71d2ef6620f739a117d1dd6a0cd4647630f9d937 (patch) | |
tree | 981d3f58c45c333e0f6451e1bfbb945666e27ea3 | |
parent | 9cabdb383f18e0e1b8dd0d66f19aa62cf498899b (diff) | |
download | snc-71d2ef6620f739a117d1dd6a0cd4647630f9d937.tar.gz snc-71d2ef6620f739a117d1dd6a0cd4647630f9d937.tar.bz2 snc-71d2ef6620f739a117d1dd6a0cd4647630f9d937.zip |
roman to arabic: fix accepting incorrect roman value
-rw-r--r-- | snc.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -35,8 +35,15 @@ int romanToArabic(char *str) amount_char = 1; } else if(last_value < cur_value) { + if(last_value * 10 < cur_value) + return -1; + else if(last_value == SNC_ROMAN_V || + last_value == SNC_ROMAN_L || last_value == SNC_ROMAN_D) + return -1; + answer += cur_value - 2 * last_value; - if(amount_char > 1) return -1; + if(amount_char > 1) + return -1; amount_char = 1; } last_value = cur_value; |