题解 | 简单错误记录

简单错误记录

https://www.nowcoder.com/practice/2baa6aba39214d6ea91a2e03dff3fbeb

package main

import (
	"fmt"
	"strings"
)

func main() {
	cache := make(map[string]int)
	order := []string{}
	var a, b string
	for {
		n, _ := fmt.Scan(&a, &b)
		if n == 0 {
			break
		} else {
			arr := strings.Split(a, "\\")
			file := arr[len(arr)-1]
			if len(file) > 16 {
				file = file[len(file)-16 : len(file)]
			}
			_, ok := cache[file+" "+b]
			if ok {
				cache[file+" "+b] += 1
			} else {
				cache[file+" "+b] = 1
				order = append(order, file+" "+b)
			}
		}
	}
	if len(order) > 8 {
		order = order[len(order)-8 : len(order)]
	}
	for i := 0; i < len(order); i++ {
		tmp := strings.Split(order[i], " ")
		fmt.Printf("%s %s %d\n", tmp[0], tmp[1], cache[order[i]])
	}
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务