CCC '12 S2 - Aromatic Numbers

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 256M

Problem type
Canadian Computing Competition: 2012 Stage 1, Senior #2

This question involves calculating the value of aromatic numbers which are a combination of Arabic digits and Roman numerals.

An aromatic number is of the form ARARAR \dots AR, where each A is an Arabic digit, and each R is a Roman numeral. Each pair AR contributes a value described below, and by adding or subtracting these values together we get the value of the entire aromatic number.

An Arabic digit A can be 0, 1, 2, 3, 4, 5, 6, 7, 8 or 9. A Roman numeral R is one of the seven letters I, V, X, L, C, D, or M. Each Roman numeral has a base value:

Symbol I V X L C D M
Base value 1 5 10 50 100 500 1000

The value of a pair AR is A times the base value of R. Normally, you add up the values of the pairs to get the overall value. However, wherever there are consecutive symbols ARA^{\prime}R^{\prime} with R^{\prime} having a strictly bigger base value than R, the value of pair AR must be subtracted from the total, instead of being added.

For example, the number 3M1D2C has the value 3 \times 1000 + 1 \times 500 + 2 \times 100 = 3700 and 3X2I4X has the value 3 \times 10 - 2 \times 1 + 4 \times 10 = 68.

Write a program that computes the values of aromatic numbers.

Input Specification

The input is a valid aromatic number consisting of between 2 and 20 symbols.

Output Specification

The output is the decimal value of the given aromatic number.

Sample Input 1

3M1D2C

Output for Sample Input 1

3700

Sample Input 2

2I3I2X9V1X

Output for Sample Input 2

-16

Comments


  • 1
    jrkws  commented on April 20, 2024, 8:36 p.m.

    For sample input 2:

    2I3I2X9V1X = 2×1 + 3×1 + 2×10 + 9×5 + 1×10

    However, wherever there are consecutive symbols ARA'R' with R' having a strictly bigger base value than R, the value of pair AR must be subtracted from the total, instead of being added.

    This means that 3×1 + 2×10 becomes -3×1 + 2×10 and 9×5 + 1×10 becomes -9×5 + 1×10. So the equation is rewritten as:

    2I3I2X9V1X = 2×1 - 3×1 + 2×10 - 9×5 + 1×10 = -16

    Hope this helps :)


  • 1
    XianBinChen0712  commented on Jan. 13, 2024, 3:16 a.m.

    Confusing cuz' no explanation


  • 14
    Tommy_Shan  commented on Sept. 1, 2021, 6:37 p.m.

    Just a note, subtract AR NOT A'R'

    However, wherever there are consecutive symbols ARA′R′ with R′ having a strictly bigger base value than R, the value of pair AR must be subtracted from the total, instead of being added.


  • 11
    Badmode  commented on Jan. 22, 2021, 5:18 a.m.

    I am confusion


  • 16
    John  commented on Sept. 14, 2020, 3:33 p.m.

    This problem is extremely unclear and needs revised instructions, as well as an explanation for at least one sample. It should be harder to complete the coding challenge than to actually read the instructions for it.


    • 10
      c  commented on Sept. 14, 2020, 8:54 p.m.

      DMOJ does not generally modify problem statements that we get from other sources (this is a CCC problem).

      If you have any feedback about CCC feel free to get in touch with the CEMC.


  • 21
    kylezheng7  commented on May 16, 2020, 9:01 p.m.

    Can dmoj not speak english?


  • 35
    GD_FrostByte  commented on Nov. 17, 2019, 2:37 p.m. edited

    confusion noises


  • 5
    Evanhyd  commented on Oct. 29, 2019, 11:03 p.m.

    Note: From the example 3X2I4X, because 2I(AR)'s base is smaller than 4X(A′R′), so 2I(AR) should be subtracted from the total(-2 * I = -2 * 1)


  • -48
    bobhob314  commented on Jan. 6, 2015, 12:24 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.