Strings as objects

Report a typo

You need to decode a string:

  • If the string's first symbol is i, remove the first symbol. The string will contain a number. Add 1 to the number and print it.
  • If the string's first symbol is s, remove the first symbol. Then print the reversed remainder.
  • If otherwise, print the unchanged string.

Here are string functions that you can use:

  • .first() returns the first symbol of the string.
  • .isEmpty() returns true if the string has no symbols, otherwise, it returns false.
  • .drop(n) removes n first symbols from the string and returns the resulting string.
  • .reversed() returns the reversed string.
  • .toInt() converts the string to an integer and returns it.

You should output the results using the println function.

You may read about characters in our topic. Advanced string operations are covered here. However, the above functions should be enough to solve this problem.

Sample Input 1:

i123

Sample Output 1:

124

Sample Input 2:

sabc

Sample Output 2:

cba

Sample Input 3:


Sample Output 3:


Write a program in Kotlin
fun main() {
val input = readLine()!!
// write code here
}
___

Create a free account to access the full topic