HDU 2352 Verdis Quo(模拟)
来源:互联网 发布:练字软件app 编辑:程序博客网 时间:2024/05/20 15:39
H - Verdis Quo HDU 2352
Time Limit: 1000 MS Memory Limit: 32768 KB
64-bit integer IO format: %I64d , %I64u Java class name: Main
[Submit] [Status]
Description
The Romans used letters from their Latin alphabet to represent each of the seven numerals in their number system. The list below shows which
letters they used and what numeric value each of those letters represents:
I = 1
V = 5
X = 10
L = 50
C = 100
D = 500
M = 1000
Using these seven numerals, any desired number can be formed by following the two basic additive and subtractive rules. To form a number using
the additive rule the Roman numerals are simply written from left to right in descending order, and the value of each roman numeral is added
together. For example, the number MMCLVII has the value 1000 + 1000 + 100 + 50 + 5 + 1 + 1 = 2157. Using the addition rule alone could lead to
very long strings of letters, so the subtraction rule was invented as a result. Using this rule, a smaller Roman numeral to the left of a larger one is
subtracted from the total. In other words, the number MCMXIV is interpreted as 1000 - 100 + 1000 + 10 - 1 + 5 = 1914.
Over time the Roman number writing system became more standardized and several additional rules were developed. The additional rules used today
are:
1. The I, X, or C Roman numerals may only be repeated up to three times in succession. In other words, the number 4 must be represented as IV
and not as IIII.
2. The V, L, or D numerals may never be repeated in succession, and the M numeral may be repeated as many 2. times as necessary.
3. Only one smaller numeral can be placed to the left of another. For example, the number 18 is represented as XVIII but not as XIIX.
4. Only the I, X, or C can be used as subtractive numerals.
5. A subtractive I can only be used to the left of a V or X. Likewise a X can only appear to the left of a L or C, and a C can only be used to the
left of a D or M. For example, 49 must be written as XLIX and not as IL.
Your goal is to write a program which converts Roman numbers to base 10 integers.
letters they used and what numeric value each of those letters represents:
I = 1
V = 5
X = 10
L = 50
C = 100
D = 500
M = 1000
Using these seven numerals, any desired number can be formed by following the two basic additive and subtractive rules. To form a number using
the additive rule the Roman numerals are simply written from left to right in descending order, and the value of each roman numeral is added
together. For example, the number MMCLVII has the value 1000 + 1000 + 100 + 50 + 5 + 1 + 1 = 2157. Using the addition rule alone could lead to
very long strings of letters, so the subtraction rule was invented as a result. Using this rule, a smaller Roman numeral to the left of a larger one is
subtracted from the total. In other words, the number MCMXIV is interpreted as 1000 - 100 + 1000 + 10 - 1 + 5 = 1914.
Over time the Roman number writing system became more standardized and several additional rules were developed. The additional rules used today
are:
1. The I, X, or C Roman numerals may only be repeated up to three times in succession. In other words, the number 4 must be represented as IV
and not as IIII.
2. The V, L, or D numerals may never be repeated in succession, and the M numeral may be repeated as many 2. times as necessary.
3. Only one smaller numeral can be placed to the left of another. For example, the number 18 is represented as XVIII but not as XIIX.
4. Only the I, X, or C can be used as subtractive numerals.
5. A subtractive I can only be used to the left of a V or X. Likewise a X can only appear to the left of a L or C, and a C can only be used to the
left of a D or M. For example, 49 must be written as XLIX and not as IL.
Your goal is to write a program which converts Roman numbers to base 10 integers.
Input
The input to this problem will consist of the following:
A line with a single integer "N" (1 ≤ N ≤ 1000), where N indicates how many Roman numbers are to be converted.
A series of N lines of input with each line containing one Roman number. Each Roman number will be in the range of 1 to 10,000 (inclusive)
and will obey all of the rules laid out in the problem's introduction.
A line with a single integer "N" (1 ≤ N ≤ 1000), where N indicates how many Roman numbers are to be converted.
A series of N lines of input with each line containing one Roman number. Each Roman number will be in the range of 1 to 10,000 (inclusive)
and will obey all of the rules laid out in the problem's introduction.
Output
For each of the N Roman numbers, print the equivalent base 10 integer, one per line.
Sample Input
3IXMMDCIIDXII
Sample Output
92602512
execute time:0.002066 s, 2 db queris.
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<iostream>#include<algorithm>#include<math.h>using namespace std;int n;char str[10010];int findx(char ch){ if(ch == 'I') { return 1; } if(ch == 'V') { return 5; } if(ch == 'X') { return 10; } if(ch == 'L') { return 50; } if(ch == 'C') { return 100; } if(ch == 'D') { return 500; } if(ch == 'M') { return 1000; }}int main(){ scanf("%d",&n); while(n--) { scanf("%s",str); int a[11000]; int k = 0; a[k] = findx(str[0]); for(int i=1;str[i]!='\0';i++) { if(findx(str[i-1])<findx(str[i])) { a[k] = findx(str[i]) - a[k]; } else { a[++k] = findx(str[i]); } } long long int sum = 0; for(int i=0;i<=k;i++) { sum += a[i]; } printf("%lld\n",sum); } return 0;}
0 0
- HDU 2352 Verdis Quo(模拟)
- hdu 2352 Verdis Quo
- hdu 2352 Verdis Quo
- hdu 2352 Verdis Quo
- HDU-2352(verdis quo)
- hdu 2352 Verdis Quo(水题)
- HDU—— 2352 Verdis Quo
- HDOJ/HDU 2352 Verdis Quo(罗马数字与10进制数的转换)
- Verdis Quo+map
- HDU2352 Verdis Quo
- hdoj2352 Verdis Quo
- 606第十周周六赛G - Verdis Quo罗马数字表示
- hunnu 11269 The Status is Not Quo (简单模拟)
- HDU2352Verdis Quo
- hdu 3347(模拟)
- hdu 3344(模拟)
- hdu 2142 (模拟,,,)
- hdu 1034 (模拟)
- 【三层】大神与菜鸟的区别
- Android stadio去掉标题
- Eclipse从SVN恢复本地<误删除已删除>的文件和代码
- delphi中TMemo和TStringList保存文本文件TXT时去除每行后面回车符(#13)的方法
- Java数据结构之插入排序算法
- HDU 2352 Verdis Quo(模拟)
- Insert Interval (Java)
- Android开发--桌面浮动歌词窗口
- android跑马灯效果的TextView
- hdu 3460 Ancient Printer (字典树)
- POJ 1990 MooFest 题解 《挑战程序设计竞赛》
- win7 64位,vs2010(visual studio2010)环境下配置openCV2.4.8版本,以及可能遇到的问题
- Count and Say
- ios弹菊花和推荐