fork download
  1. package main
  2.  
  3. import (
  4. "bufio"
  5. "fmt"
  6. "os"
  7. "strings"
  8. )
  9.  
  10. func transform(textBlock []string) []string {
  11. var transformedText []string
  12. t := ""
  13. longest := 0
  14. for _, line := range textBlock {
  15. if len(line) > longest {
  16. longest = len(line)
  17. }
  18. }
  19. for i := 0; i < longest; i++ {
  20. for _, line := range textBlock {
  21. if i < len(line) {
  22. t += string(line[i])
  23. } else {
  24. t += " "
  25. }
  26. }
  27. transformedText = append(transformedText, strings.TrimRight(t, " "))
  28. t = ""
  29. }
  30. return transformedText
  31. }
  32.  
  33. func main() {
  34. reader := bufio.NewReader(os.Stdin)
  35. input := "_"
  36. var textBlock []string
  37. fmt.Println("Lines to transform (blank to continue):")
  38. for input != "" {
  39. input, _ = reader.ReadString('\n')
  40. input = strings.Trim(input, " \n\r")
  41. textBlock = append(textBlock, input)
  42. }
  43. textBlock = textBlock[:len(textBlock)-1]
  44. transformedText := transform(textBlock)
  45. for _, text := range transformedText {
  46. fmt.Println(text)
  47. }
  48. }
Success #stdin #stdout 0s 790016KB
stdin
package main

import "fmt"

func main() {
    queue := make(chan string, 2)
    queue <- "one"
    queue <- "twoO"
    close(queue)
    for elem := range queue {
        fmt.Println(elem)
    }
}
stdout
Lines to transform (blank to continue):
p
a
c
k
a
g
e

m
a
i
n