포럼
문제 ICPC00294

C. Converting Romans

설명

The Roman numerals are a numeral system that originated in ancient Rome and was widely used throughout Europe well into the Late Middle Ages. It differs from the Arabic system that we mostly use today in that numbers are written with combinations of letters from the Latin alphabet, where each letter is assigned a fixed integer value. Over the years many different letters were used, which was a cause of frequent confusion. But "modern" style uses only these seven:

I | V | X | L | C | D | M 1 | 5 | 10 | 50 | 100 | 500 | 1000

A very common misunderstanding of the Roman numerals is that they use a universal subtractive syntax. In a subtractive syntax, a lower digit written before a larger digit will be subtracted from the larger digit. 4 can be written as IIII and IV \((5-1)\). Romans themselves only really used the subtractive syntax for smaller numbers. For larger numbers, it was largely avoided, to give more clarity. For example, \(499\) can be written LDVLIV, XDIX, VDIV or ID, while older sources most likely would use CDXCIX. Ain't Roman numbers fun?

You are given \(n\) numbers written in the Roman numeral system, and your task is to convert them to the regular Arabic number system.

For the purposes of this problem we will subtract any digit written to the left of a larger digit, even if they are not directly adjacent.

제약
입력 형식

The inputs starts with an integer \(0 < n \leq 10^3\). Then follow \(n\) lines, each containing up to \(3 \cdot 10^5\) Roman digits. The total number of Roman digits in the input is at most \(3 \cdot 10^5\).

출력 형식

Output the corresponding Arabic numbers, one number per line.

예제 1
입력
5
CDXCIX
ID
IV
IIIIV
IIIIIIV
출력
499
499
4
1
-1
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NCPC 2023

평가 및 의견

C. Converting Romans

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

C. Converting Romans

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8