-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay8_DictionaryAndMaps.cpp
58 lines (52 loc) · 1.36 KB
/
Day8_DictionaryAndMaps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// THE PROBLEM
// ***************************
// Given n names and phone numbers, assemble a phone book that maps friends' names to their respective phone numbers.
// You will then be given an unknown number of names to query your phone book for.
// For each name queried, print the associated entry from your phone book on a new line in the form name=phoneNumber;
// if an entry for name is not found, print Not found instead.
// Solution Created By: Dustin Kaban
// Date: June 3rd, 2020
// ***************************
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <cstring>
using namespace std;
map<string,int> addToPhoneBook(int amount)
{
map<string,int> temp;
for(int i=0;i<amount;i++)
{
string s;
int num;
cin >> s >> num;
temp.insert(pair<string,int>(s,num));
}
return temp;
}
void checkRecords(map<string,int> phoneBook)
{
string input;
while(cin >> input)
{
if(phoneBook.find(input) != phoneBook.end())
{
cout << input << "=" << phoneBook[input] << endl;
}
else
{
cout << "Not found" << endl;
}
}
}
int main() {
int n; //number of entries
cin >> n;
map<string,int> phoneBook;
phoneBook = addToPhoneBook(n);
checkRecords(phoneBook);
return 0;
}