summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-02-04 16:56:40 +0000
committerJoursoir <chat@joursoir.net>2021-02-04 16:56:40 +0000
commit71d2ef6620f739a117d1dd6a0cd4647630f9d937 (patch)
tree981d3f58c45c333e0f6451e1bfbb945666e27ea3
parent9cabdb383f18e0e1b8dd0d66f19aa62cf498899b (diff)
downloadsnc-71d2ef6620f739a117d1dd6a0cd4647630f9d937.tar.gz
snc-71d2ef6620f739a117d1dd6a0cd4647630f9d937.tar.bz2
snc-71d2ef6620f739a117d1dd6a0cd4647630f9d937.zip
roman to arabic: fix accepting incorrect roman value
-rw-r--r--snc.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/snc.c b/snc.c
index 723e64f..635e5b1 100644
--- a/snc.c
+++ b/snc.c
@@ -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;