Created
December 29, 2016 06:11
-
-
Save hygull/0ea7d6fcbe315bcef3655810ae2f2f4e to your computer and use it in GitHub Desktop.
A simple hashing problem(from hackerearh practice section) to choose a name from a hash table created by hygull - https://repl.it/EyA0/2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
#Created on : 29/12/2016. | |
#Aim of program : A simple hashing problem to choose a name from a hash table. | |
#Coded by : Rishikesh Agrawani. | |
#Problem's link : https://www.hackerearth.com/practice/data-structures/hash-tables/basics-of-hash-tables/tutorial/ | |
*/ | |
package main | |
import "fmt" | |
func main() { | |
/* | |
Visit to see the problem => | |
https://www.hackerearth.com/practice/data-structures/hash-tables/basics-of-hash-tables/tutorial/ | |
*/ | |
var n int //Number of colleagues | |
var rollNumber int //roll number of colleague | |
var queries int//Number of queries that Monk can ask to helper | |
var name string //Name of colleague | |
fmt.Scanf("%d",&n) | |
hash :=make(map[int]string) //A hash table to map names from rollnumbers | |
for i:=0;i<n;i++{ | |
fmt.Scanf("%d%s",&rollNumber,&name) | |
hash[rollNumber]=name //Storing key-value pairs | |
} | |
fmt.Scanf("%d",&queries) | |
var requestedRollNumbers []int //A list of roll numbers that Monk wants to know | |
for i:=0;i<queries;i++{ | |
fmt.Scanf("%d",&rollNumber) | |
requestedRollNumbers=append(requestedRollNumbers,rollNumber) | |
} | |
for _,rollNumber:=range requestedRollNumbers{ | |
fmt.Println(hash[rollNumber]) //Displaying the names for all queries | |
} | |
} | |
/*OUTPUT(As hackerearth wants...Visit the above mentioned link in comment) | |
5 | |
1 bhagya | |
2 hemkesh | |
3 malinikesh | |
4 chotti | |
5 glue | |
3 | |
3 | |
4 | |
2 | |
malinikesh | |
chotti | |
hemkesh | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment