Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // package main
- // import (
- // "bufio"
- // "fmt"
- // "os"
- // "sort"
- // "strconv"
- // "strings"
- // )
- // type TrieNode struct {
- // children map[string]*TrieNode
- // }
- // func NewTrieNode() *TrieNode {
- // return &TrieNode{
- // children: make(map[string]*TrieNode),
- // }
- // }
- // func insertTrieNode(root *TrieNode, path string) {
- // dirs := strings.Split(path, "/")
- // node := root
- // for _, dir := range dirs {
- // if _, ok := node.children[dir]; !ok {
- // node.children[dir] = NewTrieNode()
- // }
- // node = node.children[dir]
- // }
- // }
- // func printDirectoriesHelper(node *TrieNode, level int) {
- // keys := make([]string, 0, len(node.children))
- // for key := range node.children {
- // keys = append(keys, key)
- // }
- // sort.Strings(keys)
- // for _, key := range keys {
- // fmt.Println(strings.Repeat(" ", level) + key)
- // printDirectoriesHelper(node.children[key], level+1)
- // }
- // }
- // func printDirectories(root *TrieNode) {
- // printDirectoriesHelper(root, 0)
- // }
- // func main() {
- // scanner := bufio.NewScanner(os.Stdin)
- // buf := make([]byte, 1e6)
- // scanner.Buffer(buf, 1e6)
- // scanner.Scan()
- // n, _ := strconv.Atoi(strings.Split(scanner.Text(), " ")[0])
- // root := NewTrieNode()
- // for i := 0; i < n; i++ {
- // scanner.Scan()
- // path := scanner.Text()
- // insertTrieNode(root, path)
- // }
- // printDirectories(root)
- // }
- //------------------------------------------------------------------------------------------------
- package main
- import (
- "bufio"
- "fmt"
- "os"
- "sort"
- "strconv"
- "strings"
- )
- func main() {
- scanner := bufio.NewScanner(os.Stdin)
- buf := make([]byte, 1e6)
- scanner.Buffer(buf, 1e6)
- scanner.Scan()
- n, _ := strconv.Atoi(strings.Split(scanner.Text(), " ")[0])
- directoryPaths := make([]string, n)
- for i := 0; i < n; i++ {
- scanner.Scan()
- path := scanner.Text()
- directoryPaths[i] = path
- }
- sort.Strings(directoryPaths)
- for _, path := range directoryPaths {
- idx := strings.LastIndex(path, "/")
- count := strings.Count(path, "/")
- currentDir := path[idx+1:]
- fmt.Println(strings.Repeat(" ", count) + currentDir)
- }
- }
- //------------------------------------------------------------------------------------------------
- // package main
- // import (
- // "bufio"
- // "fmt"
- // "os"
- // "sort"
- // "strconv"
- // "strings"
- // )
- // func main() {
- // scanner := bufio.NewScanner(os.Stdin)
- // buf := make([]byte, 1e6)
- // scanner.Buffer(buf, 1e6)
- // scanner.Scan()
- // n, _ := strconv.Atoi(strings.Split(scanner.Text(), " ")[0])
- // directoryPaths := make([][]string, n)
- // var rootName string
- // for i := 0; i < n; i++ {
- // scanner.Scan()
- // path := scanner.Text()
- // directoryPaths[i] = strings.Split(path, "/")
- // rootName = directoryPaths[i][0]
- // directoryPaths[i][0] = "#"
- // }
- // sort.Slice(directoryPaths, func(i, j int) bool {
- // return strings.Join(directoryPaths[i], "/") < strings.Join(directoryPaths[j], "/")
- // })
- // for i := 0; i < len(directoryPaths); i++ {
- // for j := 0; j < len(directoryPaths[i])-1; j++ {
- // fmt.Print(" ")
- // }
- // currDir := directoryPaths[i][len(directoryPaths[i])-1]
- // if currDir == "#" {
- // fmt.Println(rootName)
- // } else {
- // fmt.Println(currDir)
- // }
- // }
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement