Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.49 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "os"
  6.     "strconv"
  7. )
  8.  
  9. func main() {
  10.     str := os.Args[1]
  11.  
  12.     current := str[0]
  13.     count := 1
  14.     result := string(current)
  15.  
  16.     for i, length := 0, len(str); i < length; i++ {
  17.         if current == str[i] {
  18.             count++
  19.         } else {
  20.             if count != 1 {
  21.                 result += strconv.Itoa(count)
  22.             }
  23.  
  24.             current = str[i]
  25.             count = 1
  26.         }
  27.  
  28.         if count == 1 {
  29.             result += string(current)
  30.         }
  31.     }
  32.  
  33.     fmt.Printf("input data: %s\n", str)
  34.     fmt.Printf("result: %s\n", result)
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement