uva 759 - The Return of the Roman Empire

 1 #include <cstdio>
 2 #include <string>
 3 #include <map>
 4 using namespace std;
 5
 6 const int SIZE = 13;
 7 const int value[] = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000};
 8 const string sign[] = {"I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"};
 9
10 int main()
11 {
12     map<string, int> dic;
13     for (int n = 1; n < 4000; n++)
14     {
15         int num = n;
16         string Roman = "";
17         for(int i = SIZE - 1; i >= 0 && num; i--)
18         {
19             while(num >= value[i])
20             {
21                 Roman += sign[i];
22                 num -= value[i];
23             }
24         }
25         dic[Roman] = n;
26     }
27
28     char s[99];
29     while(gets(s))
30     {
31         if(s[0] == ‘\0‘)
32         {
33             puts("0");
34             continue;
35         }
36         if(dic.count(s)) printf("%d\n", dic[s]);
37         else printf("This is not a valid number\n");
38     }
39     return 0;
40 }
时间: 2024-12-21 16:21:47

uva 759 - The Return of the Roman Empire的相关文章

uva 1339 Ancient Cipher(字符串处理)

uva 1339 Ancient Cipher Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping. T

uva 1339

Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping. The most popular ciphers

Leetcode 题目整理-3 Palindrome Number &amp; Roman to Integer

9. Palindrome Number Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the res

Ural 1520 Empire Strikes Back(模拟退火)

最近研究了下模拟退火,首先戳这里>_<顾研08年集训队论文,讲的非常详细 首先随机20个点作为候选解,以此扩展来确定距离工厂最近的点的最远的距离是多少.但是有需要注意到扩展点在边界的情况,因为边界是圆所以很难继续扩展,如论文中提到的两种情况.1.是两工厂垂直平分线与边界交点2.一个工厂的圆与边界相切.单独判断即可. 其中有个很蛋疼的地方,我之前距离用了很多次sqrt,T成狗,比较距离时只需比较距离平方,答案最后再开根即可 代码:https://github.com/mlz000/Ural/bl

UVa1399.Ancient Cipher

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4085 13855995 1339 Ancient Cipher Accepted C++ 0.012 2014-07-09 12:35:33 Ancient Cipher Ancient Roman empire had a strong government system wit

UVa1339

1339 Ancient CipherAncient Roman empire had a strong government system with various departments, including a secretservice department. Important documents were sent between provinces and the capital in encryptedform to prevent eavesdropping. The most

poj 2159 D - Ancient Cipher 文件加密

Ancient Cipher Description Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping

uva--1339 - Ancient Cipher(模拟水体系列)

1339 - Ancient Cipher Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping. The

poj 2159 Ancient Cipher(水)

Ancient Cipher Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30695   Accepted: 10023 Description Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents w