Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "os"
- "strconv"
- )
- func main() {
- str := os.Args[1]
- current := str[0]
- count := 1
- result := string(current)
- for i, length := 0, len(str); i < length; i++ {
- if current == str[i] {
- count++
- } else {
- if count != 1 {
- result += strconv.Itoa(count)
- }
- current = str[i]
- count = 1
- }
- if count == 1 {
- result += string(current)
- }
- }
- fmt.Printf("input data: %s\n", str)
- fmt.Printf("result: %s\n", result)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement