uva 759 - The Return of the Roman Empire

 #include <cstdio>
#include <string>
#include <map>
using namespace std; const int SIZE = ;
const int value[] = {, , , , , , , , , , , , };
const string sign[] = {"I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"}; int main()
{
map<string, int> dic;
for (int n = ; n < ; n++)
{
int num = n;
string Roman = "";
for(int i = SIZE - ; i >= && num; i--)
{
while(num >= value[i])
{
Roman += sign[i];
num -= value[i];
}
}
dic[Roman] = n;
} char s[];
while(gets(s))
{
if(s[] == '\0')
{
puts("");
continue;
}
if(dic.count(s)) printf("%d\n", dic[s]);
else printf("This is not a valid number\n");
}
return ;
}
上一篇:git基础知识总结


下一篇:python爬百度文库课件