Advertisement
Egmell

3

Apr 18th, 2024 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 3.31 KB | None | 0 0
  1. // package main
  2.  
  3. // import (
  4. //  "bufio"
  5. //  "fmt"
  6. //  "os"
  7. //  "sort"
  8. //  "strconv"
  9. //  "strings"
  10. // )
  11.  
  12. // type TrieNode struct {
  13. //  children map[string]*TrieNode
  14. // }
  15.  
  16. // func NewTrieNode() *TrieNode {
  17. //  return &TrieNode{
  18. //      children: make(map[string]*TrieNode),
  19. //  }
  20. // }
  21.  
  22. // func insertTrieNode(root *TrieNode, path string) {
  23. //  dirs := strings.Split(path, "/")
  24. //  node := root
  25.  
  26. //  for _, dir := range dirs {
  27. //      if _, ok := node.children[dir]; !ok {
  28. //          node.children[dir] = NewTrieNode()
  29. //      }
  30. //      node = node.children[dir]
  31. //  }
  32. // }
  33.  
  34. // func printDirectoriesHelper(node *TrieNode, level int) {
  35. //  keys := make([]string, 0, len(node.children))
  36. //  for key := range node.children {
  37. //      keys = append(keys, key)
  38. //  }
  39. //  sort.Strings(keys)
  40.  
  41. //  for _, key := range keys {
  42. //      fmt.Println(strings.Repeat("  ", level) + key)
  43. //      printDirectoriesHelper(node.children[key], level+1)
  44. //  }
  45. // }
  46.  
  47. // func printDirectories(root *TrieNode) {
  48. //  printDirectoriesHelper(root, 0)
  49. // }
  50.  
  51. // func main() {
  52. //  scanner := bufio.NewScanner(os.Stdin)
  53. //  buf := make([]byte, 1e6)
  54. //  scanner.Buffer(buf, 1e6)
  55.  
  56. //  scanner.Scan()
  57. //  n, _ := strconv.Atoi(strings.Split(scanner.Text(), " ")[0])
  58.  
  59. //  root := NewTrieNode()
  60. //  for i := 0; i < n; i++ {
  61. //      scanner.Scan()
  62. //      path := scanner.Text()
  63. //      insertTrieNode(root, path)
  64. //  }
  65.  
  66. //  printDirectories(root)
  67. // }
  68.  
  69. //------------------------------------------------------------------------------------------------
  70.  
  71. package main
  72.  
  73. import (
  74.     "bufio"
  75.     "fmt"
  76.     "os"
  77.     "sort"
  78.     "strconv"
  79.     "strings"
  80. )
  81.  
  82. func main() {
  83.     scanner := bufio.NewScanner(os.Stdin)
  84.     buf := make([]byte, 1e6)
  85.     scanner.Buffer(buf, 1e6)
  86.  
  87.     scanner.Scan()
  88.     n, _ := strconv.Atoi(strings.Split(scanner.Text(), " ")[0])
  89.  
  90.     directoryPaths := make([]string, n)
  91.  
  92.     for i := 0; i < n; i++ {
  93.         scanner.Scan()
  94.         path := scanner.Text()
  95.         directoryPaths[i] = path
  96.  
  97.     }
  98.     sort.Strings(directoryPaths)
  99.  
  100.     for _, path := range directoryPaths {
  101.         idx := strings.LastIndex(path, "/")
  102.         count := strings.Count(path, "/")
  103.         currentDir := path[idx+1:]
  104.         fmt.Println(strings.Repeat("  ", count) + currentDir)
  105.     }
  106. }
  107.  
  108. //------------------------------------------------------------------------------------------------
  109.  
  110. // package main
  111.  
  112. // import (
  113. //  "bufio"
  114. //  "fmt"
  115. //  "os"
  116. //  "sort"
  117. //  "strconv"
  118. //  "strings"
  119. // )
  120.  
  121. // func main() {
  122. //  scanner := bufio.NewScanner(os.Stdin)
  123. //  buf := make([]byte, 1e6)
  124. //  scanner.Buffer(buf, 1e6)
  125.  
  126. //  scanner.Scan()
  127. //  n, _ := strconv.Atoi(strings.Split(scanner.Text(), " ")[0])
  128.  
  129. //  directoryPaths := make([][]string, n)
  130. //  var rootName string
  131. //  for i := 0; i < n; i++ {
  132. //      scanner.Scan()
  133. //      path := scanner.Text()
  134. //      directoryPaths[i] = strings.Split(path, "/")
  135. //      rootName = directoryPaths[i][0]
  136. //      directoryPaths[i][0] = "#"
  137. //  }
  138. //  sort.Slice(directoryPaths, func(i, j int) bool {
  139. //      return strings.Join(directoryPaths[i], "/") < strings.Join(directoryPaths[j], "/")
  140. //  })
  141.  
  142. //  for i := 0; i < len(directoryPaths); i++ {
  143. //      for j := 0; j < len(directoryPaths[i])-1; j++ {
  144. //          fmt.Print("  ")
  145. //      }
  146. //      currDir := directoryPaths[i][len(directoryPaths[i])-1]
  147. //      if currDir == "#" {
  148. //          fmt.Println(rootName)
  149. //      } else {
  150. //          fmt.Println(currDir)
  151. //      }
  152. //  }
  153. // }
  154.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement