zoukankan      html  css  js  c++  java
  • 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])
        }
    	
    }
    

      

  • 相关阅读:
    NET微信公众号开发环境搭建(一)-了解微信由来
    JS:复制内容到剪贴板(无插件,兼容所有浏览器)
    js 压缩上传的图片方法(默认上传的是file文件)
    vue封装组件调用时绑定click事件
    vue cli3 区分开发环境,测试环境,正式环境(二)
    vue 动态修改网页标题 title
    vue移动端适配(px转vw)postcss-px-to-viewport配置
    veu创建项目,自定义配置
    vue cli3配置开发环境、测试环境、生产(线上)环境(一)
    vue封装axios
  • 原文地址:https://www.cnblogs.com/jfliuyun/p/6848483.html
Copyright © 2011-2022 走看看