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 Assume input ถูกต้อง
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่