1264 Aromatic number
2012 CCC Canadian High School student Information Science Orsay
time limit: 1 sspace limit: 128000 KBtitle level: Silver SolvingView Run ResultsTitle Description
Description
This question involves calculating the value of aromatic numbers which is a combination of Arabic digits and Roman Numera Ls.
The question is about the calculation of the value of the aromatic number, which is a combination of Arabic and Roman numerals.
An aromatic number is of the form Ararar ... AR, where each A is a Arabic digit, and all 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 T He entire aromatic number.
The format of the aromatic number is ararar. ARA, where a represents Arabic numerals, and R represents Roman numerals. Each pair of AR calculates a value according to the following calculation, by adding these values together, the value of the entire aromatic number is obtained.
An Arabic digit A can is 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 have a base value:
Arabic numerals are 0,1,2..9, and Roman numerals are i,v,x,l,c,d,m.
Symbol I V X L C D M Base value 1 5 10 50 100 500 1000
The value of the symbol I V X L C D m is 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 Val Ue. However, wherever there is consecutive symbols ara0r0 with R0 have a strictly bigger base value than R, the value of PA IR AR must is subtracted from the total, instead of being added.
The value of a pair of AR is computed as a multiplied by R. In general, we add up all the AR values to get the value of the aromatic number. However, if there are two consecutive number pairs of ara0r0, where R0 is strictly greater than r, then the value of AR should be subtracted instead of added.
For example, the number 3m1d2c have the value 3∗1000+1∗500+2∗100 = 3700 and 3x2i4x has the value 3∗10−2∗1 + 4∗10 = 68.
For example, the value of 3M1D2C is 3*1000+1*500+2*100=3700, and the value of 3x2i4x is 3*10-2*1+4*10=68
Write a program that computes the values of aromatic numbers.
Your task is to write a program to calculate the value of a given aromatic number.
Enter a description
Input Description
The input is a valid aromatic number consisting of between 2 and symbols.
The input is a valid aromatic number that contains 2-20 characters.
Output description
Output Description
The output is the decimal value of the given aromatic number.
The output is a decimal integer representing the value of this aromatic number.
Sample input
Sample Input
Sample Input 1:3M1D2C
Sample Input 2:2i3i2x9v1x
Sample output
Sample Output
Sample Output 1:3,700
Sample Output 2:16
Data range and Tips
Data Size & HintCategory labels
Tags Click here to expand
No difficulty.
#include <iostream>#include<cstdio>#include<cstring>#include<map>using namespaceStd;map<int,int>G;Chars[ +];inttot;intMain () {g['I']=1, g['V']=5, g['X']=Ten, g['L']= -, g['C']= -, g['D']= -, g['M']= +; scanf ("%s", s); for(intI=0; I<strlen (s); i++){ if(i%2==1){ if(g[s[i]]<g[s[i+2]]) tot-= (s[i-1]- -)*G[s[i]]; Elsetot+ = (s[i-1]- -)*G[s[i]]; }} printf ("%d\n", tot); return 0;}
1264 aromatic number