Skip to content

Instantly share code, notes, and snippets.

@szhilkin
Created January 11, 2024 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szhilkin/b232bef40a10bf630f9e068e888439a7 to your computer and use it in GitHub Desktop.
Save szhilkin/b232bef40a10bf630f9e068e888439a7 to your computer and use it in GitHub Desktop.
Тинькофф SRE задача с сайта
package main
import (
"fmt"
)
func encode(s string) string {
var res = ""
count := 1
chars := []rune(s)
for i := 1; i < len(chars); i++ {
if chars[i] == chars[i-1] {
count++
} else {
if count == 1 {
res = res + fmt.Sprint(string(chars[i-1]))
} else {
res = res + fmt.Sprint(string(chars[i-1]), count)
}
count = 1
}
}
if count > 1 {
res = res + fmt.Sprint(string(chars[len(chars)-1]), count)
}
return res
}
func main() {
fmt.Println(encode("ABBBCCDDAAABBBBBФФФФЫSS"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment