设为首页 加入收藏

TOP

golang map
2017-09-30 13:23:26 】 浏览:6761
Tags: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

1N1051≤N≤105

1RollNumber1091≤RollNumber≤109

1|Name|251≤|Name|≤25

1q1041≤q≤104

1x1091≤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 队列 下一篇go语言学习之路六:接口详解

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目