fork download
  1. a=raw_input()
  2. g=range
  3. b=list(set(a))+[' ']*9
  4. from itertools import*
  5. c=[]
  6. s={}
  7. u=1000
  8. for i in g(10*u):
  9. t,f=(10*u,9*u,5*u,4*u,u,900,500,400,100,90,50,40,10,9,5,4,1),i;r=""
  10. for j in g(17):k=i/t[j];r+=('W^MW^Q^MQ^M^CM^D^CD^C^XC^L^XL^X^IX^V^IV^I').split('^')[j]*k;i-=t[j]*k
  11. s[r]=f
  12. for i in permutations(b[:9]):
  13. r=''
  14. for j in a:r+='IVXLCMQWE'[i.index(j)]
  15. if r in s:c+=[s[r]]
  16. print c and min(c)or'%s failed Roman numeral test'%a
Success #stdin #stdout 2.96s 9248KB
stdin
AaBbcDEf
stdout
AaBbcDEf failed Roman numeral test