Roman numerals · מספרים רומיים
Roman numerals
Convert a Roman numeral to an int. The symbols are I=1, V=5, X=10, L=50, C=100, D=500, M=1000. Usually you add, but when a smaller symbol sits before a larger one you subtract it: IV is 4, IX is 9, MCMXCIV is 1994. Scanning from right to left makes the subtract rule easy — subtract any symbol smaller than the one to its right.
מספרים רומיים
המרה ממספר רומי ל-int. הסמלים הם I=1, V=5, X=10, L=50, C=100, D=500, M=1000. בדרך כלל מחברים, אך כאשר סמל קטן ממוקם לפני סמל גדול, מחסרים אותו: IV הוא 4, IX הוא 9, ו-MCMXCIV הוא 1994. סריקה מימין לשמאל הופכת את כלל ההחסרה לקלה — חסור כל סמל הקטן מהסמל שמאלה לו.
Complete romanToInt(String s) converting a Roman numeral to an int. A smaller symbol before a larger one is subtracted, so IV is 4 and MCMXCIV is 1994. Assume valid input. · השלם את romanToInt(String s) להמרת מספר רומי למספר int. סמל קטן לפני סמל גדול נחסר, ולכן IV הוא 4 ו-MCMXCIV הוא 1994. הנח כי הקלט תקין.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.