Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <map>
- #include <string>
- #include <utility>
- using namespace std;
- int main() {
- map<string, int> states;
- states.insert(pair<string, int>("Maharashtra", 9823456));
- states.insert(pair<string, int>("Uttarakhand", 6801234));
- states.insert(pair<string, int>("Karnataka", 8593589));
- states.insert(pair<string, int>("Delhi", 9123456));
- states.insert(pair<string, int>("Meghalaya", 3410923));
- states.insert(pair<string, int>("Assam", 79812389));
- states.insert(pair<string, int>("Rajasthan", 69239485));
- states.insert(pair<string, int>("Punjab", 1234563));
- states.insert(pair<string, int>("Sikkim", 59234582));
- map<string, int>::iterator it;
- for (it = states.begin(); it != states.end(); ++it) {
- cout << left << setw(12) << it->first << ": " << right << setw(8) << it->second << endl;
- }
- cout << "\nThe number of States are: " << states.size() << endl;
- string name;
- cout << "\nEnter the name of the State: "; cin >> name;
- it = states.find(name);
- if (it != states.end()) {
- cout << "\nMatch Found" << endl;
- cout << setw(12) << left << name << ": " << setw(8) << right << it->second << endl;
- cout << endl;
- } else {
- cout << "\nNo Match Found" << endl;
- cout << endl;
- }
- }
- /* OUTPUT
- Assam : 79812389
- Delhi : 9123456
- Karnataka : 8593589
- Maharashtra : 9823456
- Meghalaya : 3410923
- Punjab : 1234563
- Rajasthan : 69239485
- Sikkim : 59234582
- Uttarakhand : 6801234
- The number of States are: 9
- Enter the name of the State: Sikkim
- Match Found
- Sikkim : 59234582
- Assam : 79812389
- Delhi : 9123456
- Karnataka : 8593589
- Maharashtra : 9823456
- Meghalaya : 3410923
- Punjab : 1234563
- Rajasthan : 69239485
- Sikkim : 59234582
- Uttarakhand : 6801234
- The number of States are: 9
- Enter the name of the State: Kerala
- No Match Found
- */
Advertisement
Add Comment
Please, Sign In to add comment