Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ex3ndr.romanian
- fun getValue(symbol: Char):Int
- {
- return when(symbol)
- {
- 'I' -> 1
- 'V' -> 5
- 'X' -> 10
- 'L' -> 50
- 'C' -> 100
- 'D' -> 500
- 'M' -> 1000
- }
- }
- fun main(args : Array<String>) {
- if (args.size != 1)
- {
- System.out?.println("Usage: <data>")
- return
- }
- val data = args.get(0);
- System.out?.println("Input: ${data}")
- var res = 0
- var lastValue = 0;
- for(i in 0..data.length-1)
- {
- val currentValue = getValue(data[i])
- if (currentValue >= lastValue)
- res += currentValue
- else
- res -= currentValue
- lastValue = currentValue
- }
- System.out?.println("Output: ${res}")
- }
Advertisement
Add Comment
Please, Sign In to add comment