golang map
Our friend Monk has been made teacher for the day today by his school professors . He is going to teach informatics to his colleagues as that is his favorite subject . Before entering the class, Monk realized that he does not remember the names of all his colleagues clearly . He thinks this will cause problems and will not allow him to teach the class well. However, Monk remembers the roll number of all his colleagues very well . Monk now wants you to help him out. He will initially give you a list indicating the name and roll number of all his colleagues. When he enters the class he will give you the roll number of any of his colleagues belonging to the class. You need to revert to him with the name of that colleague.
Input Format
The first line contains a single integers NN denoting the number of Monk's colleagues. Each of the next NN lines contains an integer and a String denoting the roll number and name of the ii th colleague of Monk. The next Line contains a single integer qq denoting the number of queries Monk shall present to you when he starts teaching in class. Each of the next qq lines contains a single integer xx denoting the roll number of the student whose name Monk wants to know.
Output Format
You need to print qq Strings, each String on a new line, indicating the answers to each of Monk's queries.
Constrains
1≤N≤1051≤N≤105
1≤RollNumber≤1091≤RollNumber≤109
1≤|Name|≤251≤|Name|≤25
1≤q≤1041≤q≤104
1≤x≤1091≤x≤109
Note
The name of each student shall consist of lowercase English alphabets only. It is guaranteed that the roll number appearing in each query shall belong to some student from the class.
其实就是用到了golang 数据集合map,貌似Map的性能不是太好
package main
import "fmt"
func main() {
	//fmt.Println("Hello World!")
	 mapDic := make(map[int]string)
	var mapCount int
	fmt.Scanln(&mapCount)
	var key int
	var value string
	for i:=0;i<mapCount;i++{
	    fmt.Scanln(&key, &value)
	    mapDic[key] = value
	}
	var searchCount int
    fmt.Scanln(&searchCount)
    var searchKey int
    for j:=0;j<searchCount;j++{
         fmt.Scanln(&searchKey)
         fmt.Println(mapDic[searchKey])
    }
}
golang map的更多相关文章
- 【GoLang】GoLang map 非线程安全 & 并发度写优化
		
Catena (时序存储引擎)中有一个函数的实现备受争议,它从 map 中根据指定的 name 获取一个 metricSource.每一次插入操作都会至少调用一次这个函数,现实场景中该函数调用更是频繁 ...
 - golang map输出排序
		
由于GoLang Map 内部存储是无序的,当需要按顺序获得map存储的key -value值时,应该对遍历出来的结果进行重新排序: 在go 1.8版本后,提供的slice sort 功能使排序更简单 ...
 - Golang Map实现(一)
		
本文学习 Golang 的 Map 数据结构,以及map buckets 的数据组织结构. hash 表是什么 从大学的课本里面,我们学到:hash 表其实就是将key 通过hash算法映射到数组的某 ...
 - Golang Map实现(四) map 的赋值和扩容
		
title: Golang Map 实现 (四) date: 2020-04-28 18:20:30 tags: golang map 操作,是map 实现中较复杂的逻辑.因为当赋值时,为了减少has ...
 - golang  map  getkeys
		
golang 获取map的keys package main import "fmt" import "reflect" func main() { abc : ...
 - golang map 读写锁与深度拷贝的坑
		
0X01 golang中,map(字典)无法并发读写 简单来说,新建万条线程对同一个map又读又写,会报错. 为此,最好加锁,其实性能影响并不明显. type taskCache struct{ sy ...
 - Golang map 如何进行删除操作?
		
Cyeam 关注 2017.11.02 10:02* 字数 372 阅读 2784评论 0喜欢 3 map 的删除操作 Golang 内置了哈希表,总体上是使用哈希链表实现的,如果出现哈希冲突,就把冲 ...
 - Golang map并发 读写锁
		
golang并发 一:只有写操作 var ( count int l = sync.Mutex{} m = make(map[int]int) ) //全局变量并发写 导致计数错误 func vari ...
 - Golang Map Addressability
		
http://wangzhezhe.github.io/blog/2016/01/22/golangmapaddressability-dot-md/ 在golang中关于map可达性的问题(addr ...
 
随机推荐
- DOMContentLoaded、readystatechange、load、ready详谈
			
对前端同学而言,loade,unload,DOMContentLoaded等页面加载过程中会触发的事件肯定是都接触过,不过要是具体问各个事件的区别,我就不是那么能清晰的解答上来的了.正好刚刚在无阻塞脚 ...
 - 通过ssh訪问NAT网络模式虚拟机里的Linux
			
进入 GuestOS : #/sbin/ifconfig 查看 inet addr : 10.0.2.15 然后到 HostOS 去, 看控制面板, 看网络和共享中心的VirtualBox Host- ...
 - linux 开机批量启动程序
			
每天早上到公司第一件事打开电脑,打开我的qq.我的开发工具idea.在看看邮件,日复一日,变懒了.也变聪明了,写了以下一段脚本 文件名称:mystart.sh #!bin/bash #检验我的开发工具 ...
 - Error code:1728 Cannot load from mysql.proc. The table is probably corrupted
			
Error code:1728 Cannot load from mysql.proc. The table is probably corrupted http://bugs.mysql.com/b ...
 - laravel会话驱动扩展—连接自定义会话管理系统
			
laravel 版本:5.3.* 用laravel开发公司信息系统过程中,由于业务或安全问题的考虑,会有一些特殊的用户会话管理方面的需求,如多个子系统会话统一管理或A系统业务操作导致B系统中某些在线用 ...
 - Ajax 请求后打开新窗口被拦截的解决方案
			
公司业务上有个场景,需请求后台获取支付链接地址,再打开地址引导用户购买.这样的场景在其他企业应该也很场景.但是遇到个很常见的问题,Ajax后直接用window.open(url),会被浏览器作为广告拦 ...
 - (转)spring aop
			
工作忙,时间紧,不过事情再多,学习是必须的.记得以前的部门老大说过:“开发人员不可能一天到晚只有工作,肯定是需要自我学习.第一:为了更充实自己,保持进步状态.第二:为了提升技术,提高开发能力.第三:保 ...
 - CentOS6.9下安装rabbitmq消息队列
			
安装如下步骤: 首先安装erlang yum install erlang 安装rabbitmq rpm包 wget http://www.rabbitmq.com/releases/rabbitmq ...
 - 关于close和shutdown
			
我们知道TCP是全双工的,可以在接收数据的同时发送数据.假设有主机A在和主机B通信,可以认为是在两者之间存在两个管道.就像这样:A ---------> BA <--------- B 1 ...
 - 《极客与团队》【PDF】下载
			
<极客与团队>[PDF]下载链接: https://u253469.ctfile.com/fs/253469-231196337 内容简介 软件开发是一项团队运动,人的因素对结果的影响完全 ...