题解 | 简单错误记录

简单错误记录

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]])
	}
}

全部评论

相关推荐

04-29 22:35
门头沟学院 Java
牛友说改了名字能收到offer:旧图新发查看图片
点赞 评论 收藏
分享
ZywOo_求职版:谁问你了....
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-20 14:01
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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