Advertisement
SmartGenius

Number to Roman Conversion in Batch

Jul 6th, 2012
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. @Echo Off
  2. Setlocal enabledelayedexpansion
  3. Title Number to Roman Conversion
  4.  
  5. ::Coded by SmartGenius
  6.  
  7. Set "R=1"
  8. Set "R_1=. M MM MMM"
  9. Set "R_2=. C CC CCC CD D DC DCC DCCC CM"
  10. Set "R_3=. X XX XXX XL L LX LXX LXXX XC"
  11. Set "R_4=. I II III IV V VI VII VIII IX"
  12.  
  13. :Input
  14. Set /p "N=Enter Number > "
  15. If Not Defined N Cls & Goto :Input
  16. If 0 GEQ %N% (Echo.Fuera de Rango&Goto :Input)
  17. If 3999 LSS %N% (Echo.Fuera de Rango&Goto :Input)
  18.  
  19. :Split
  20. Set /a "M_O=N%%10"
  21. Set /a "M_T=(N%%100)-M_O"
  22. Set /a "M_C=(N%%1000)-(M_T+M_O)"
  23. Set /a "M_M=N-(M_C+M_T+M_O)"
  24.  
  25. :Convert
  26. Set "Sp= %M_M:~0,1%%M_C:~0,1%%M_T:~0,1%%M_O:~0,1%"
  27. :R_to_N
  28. If 5 EQU %R% (Set "RF=!RF:.=!"&Goto :Show)
  29. Set /a "T=!Sp:~%R%,1!+1"
  30. For /f "tokens=%T%" %%b in ('Echo.!R_%R%!') do (Set "RF=!RF!%%b")
  31. Set /a "R+=1"
  32. Goto :R_to_N
  33.  
  34. :Show
  35. Echo. Number = %N%
  36. Echo. Roman = %RF%
  37. Echo.
  38. Pause
  39. Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement