For a number written in Roman numerals to be considered valid there are basic rules which must be followed. Even though the rules allow some numbers to be expressed in more than
one way there is always a "best" way of writing a particular number.

For example, it would appear that there are at least six ways of writing the number sixteen:

IIIIIIIIIIIIIIII

VIIIIIIIIIII

VVIIIIII

XIIIIII

VVVI

XVI

However, according to the rules only XIIIIII and XVI are valid,
and the last example is considered to be the most efficient, as it uses the least number of numerals.

The 11K text file, roman.txt (right
click and 'Save Link/Target As...'), contains one thousand numbers written in valid, but not necessarily minimal, Roman numerals; see About...
Roman Numerals
 for the definitive rules for this problem.

Find the number of characters saved by writing each of these in their minimal form.

Note: You can assume that all the Roman numerals in the file contain no more than four consecutive identical units.

化简成最简格式无非就是遇到DCCCC变成CM,LXXXX变成XC,VIIII变成IX,IIII变成IV,XXXX变成XL,CCCC变成CD

反正遇到这种这些字符最后都变成2个字符

import re

ans=0
for line in open("roman.txt"):
a=len(line)
line=re.sub('DCCCC|LXXXX|VIIII|CCCC|XXXX|IIII','aa',line)
b=len(line)
ans=ans+a-b print(ans)

Project Euler:Problem 89 Roman numerals的更多相关文章

  1. Project Euler:Problem 63 Powerful digit counts

    The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is ...

  2. Project Euler:Problem 55 Lychrel numbers

    If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...

  3. Project Euler:Problem 86 Cuboid route

    A spider, S, sits in one corner of a cuboid room, measuring 6 by 5 by 3, and a fly, F, sits in the o ...

  4. Project Euler:Problem 76 Counting summations

    It is possible to write five as a sum in exactly six different ways: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 ...

  5. Project Euler:Problem 87 Prime power triples

    The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is ...

  6. Project Euler:Problem 93 Arithmetic expressions

    By using each of the digits from the set, {1, 2, 3, 4}, exactly once, and making use of the four ari ...

  7. Project Euler:Problem 39 Integer right triangles

    If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exact ...

  8. Project Euler:Problem 28 Number spiral diagonals

    Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is forme ...

  9. Project Euler:Problem 47 Distinct primes factors

    The first two consecutive numbers to have two distinct prime factors are: 14 = 2 × 7 15 = 3 × 5 The ...

随机推荐

  1. 【homework week5】初步了解敏捷开发——自由与约束的哲学统一

    “自由与束缚的哲学统一”或许不该放到标题上去,毕竟它只是我灵光一闪的感悟.但这个spark让我感到高中到大学的哲学应该也没有白学,这是让人非常兴奋的一件事. 所以我还是把它放到了标题上. 来谈敏捷软件 ...

  2. Solr配置Ikanalyzer分词器

    上一篇文章讲解在win系统中如何安装solr并创建一个名为test_core的Core,接下为text_core配置Ikanalyzer 分词器 1.打开text_core的instanceDir目录 ...

  3. SEO相关

    前端需要注意哪些SEO 合理的title.description.keywords: -- 搜索对着三项的权重逐个减小,title值强调重点即可,重要关键词出现不要超过2次,而且要靠前,不同页面tit ...

  4. 【转】Unity3d中制作Loading场景进度条所遇到的问题 LoadLevelAsync,AsyncOperation

    背景 通常游戏的主场景包含的资源较多,这会导致加载场景的时间较长.为了避免这个问题,可以首先加载Loading场景,然后再通过Loading场景来加载主场景.因为Loading场景包含的资源较少,所以 ...

  5. BZOJ 3990: [SDOI2015]排序(搜索+剪枝)

    [SDOI2015]排序 Description 小A有一个1-2^N的排列A[1..2^N],他希望将A数组从小到大排序,小A可以执行的操作有N种,每种操作最多可以执行一次,对于所有的i(1< ...

  6. python2.7运行出现的Warning: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal

    运行出现如下错误 uncode编码警告:在unicode等价比较中,把两个参数同时转换为unicode编码失败.中断并认为他们不相等. windows下的字符串str默认编码是ascii,而pytho ...

  7. boost 库的下载和编译_Visual Studio 2013(转)

    原文转自 http://blog.csdn.net/lp310018931/article/details/47791143 原文转自 http://m.blog.csdn.net/article/d ...

  8. 关于main函数的参数

    #include <stdio.h> int main(int argc, char const *argv[]) { int i; for ( i = 0; i < argc; i ...

  9. Codeforces Gym101063 C.Sleep Buddies (2016 USP-ICMC)

    C.Sleep Buddies It is nighttime in the Earth Colony on Mars and everyone is getting ready to sleep. ...

  10. C++多线程(POSIX)

    #include<iostream> #include<pthread.h> #include<ctime> #include<windows.h> u ...