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

      

  • 相关阅读:
    实验十四
    2
    解一元二次方程
    第一题
    输入四个人的年龄和姓名,排序后,按年龄,从小到大输出人员年龄及其姓名
    实验九
    实验8数组2 1.程序调试
    实验七4编写程序,输入一批学生的成绩,遇0或负数则输入结束,要求统计并输出优秀(大于85)、通过(60~84)和不及格(小于60)的学生人数。
    实验10 指针2
    作业4
  • 原文地址:https://www.cnblogs.com/jfliuyun/p/6848483.html
Copyright © 2020-2023  润新知