Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<map>
- #include<string>
- #include<cctype>
- void printResult(const std::map<std::string, std::string>& contacts, char searchedLetter) {
- int contactsCount = 0;
- for (auto it = contacts.begin(); it != contacts.end(); it++)
- {
- if (it->first[0] == searchedLetter)
- {
- std::cout << it->first << " " << it->second << std::endl;
- contactsCount++;
- }
- }
- if (contactsCount == 0 )
- {
- std::cout << "There are no contacts with such first letter" << std::endl;
- }
- }
- int main() {
- std::map<std::string, std::string>contacts = {
- {"Georgi", "0886123456"},
- {"Pesho", "0898435689"},
- {"Petar", "0898255689"},
- {"Ivan", "0876235416"},
- {"Tania", "052236589"},
- {"Silvia", "0982323456"},
- {"Gergana", "058236448"},
- {"Dimitar", "0884895456"},
- {"Pavlina", "0888456789"},
- {"Doncho", "0982456789"},
- {"Ivanina", "0882456789"},
- };
- contacts.insert(std::make_pair("Iliana", "0888935416"));
- contacts.erase("Petar");
- std::cout << "Enter a letter" << std::endl;
- char searchedLetter;
- std::cin >> searchedLetter;
- if (islower(searchedLetter))
- {
- searchedLetter = toupper(searchedLetter);
- }
- printResult(contacts, searchedLetter);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment