Created
January 11, 2024 02:44
-
-
Save szhilkin/b232bef40a10bf630f9e068e888439a7 to your computer and use it in GitHub Desktop.
Тинькофф SRE задача с сайта
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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