fork download
  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. "strconv"
  6. "encoding/csv"
  7. )
  8.  
  9. func f888(input string) {
  10. tmp := strings.NewReplacer("[","","]",""," ","").Replace(input)
  11. r := csv.NewReader(strings.NewReader(tmp))
  12.  
  13. var result [][]byte
  14. for {
  15. values, err := r.Read();
  16. if err != nil {
  17. break
  18. }
  19. col, _ := strconv.Atoi(values[1])
  20. line, _ := strconv.Atoi(values[2])
  21. if len(result) <= line {
  22. tmp := make([][]byte, line+1)
  23. copy(tmp, result)
  24. result = tmp
  25. }
  26. if len(result[line]) <= col {
  27. tmp := make([]byte, col+1)
  28. copy(tmp, result[line])
  29. for i := len(result[line]); i < len(tmp); i++ {
  30. tmp[i] = ' '
  31. }
  32. result[line] = tmp
  33. }
  34. result[line][col]=values[0][0]
  35. }
  36. for _, l := range result {
  37. fmt.Printf("%s\n", string(l))
  38. }
  39. }
  40.  
  41. func main(){
  42. f888("[a, 0, 0]\n[b, 2, 0]\n[c, 4, 0]\n[d, 0, 2]")
  43. }
  44.  
Success #stdin #stdout 0s 3132KB
stdin
Standard input is empty
stdout
a b c

d