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

      

  • 相关阅读:
    Rewrite the master page form action attribute in asp.net 2.0
    Using Output Cache
    An invalid character was found in text content!
    Microsoft Football Scoreboard
    A typical ASP.NET 2.0 Configuration Settings
    Visual Studio 2005 Web Application Projects Released!
    Test Driven Development with Visual Studio 2005 Team System
    How to pass a parameter to HyperLink in GridView/DataList
    MS的一个BUG折腾我几个小时!
    Create builtin tables in your own database to handle exceptions, Part 2
  • 原文地址:https://www.cnblogs.com/jfliuyun/p/6848483.html
Copyright © 2020-2023  润新知