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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
// main.cpp
// FunWithSTL
//
// Created by Aaron on 10/26/15.
// Copyright © 2015 Aaron. All rights reserved.
//
#include <iostream>
#include <string>
#include <utility>
#include <iterator>
#include <unordered_map>
#include <list>
#include <vector>
#include <stack>
using namespace std;
typedef unordered_map<string, int > scorecard;
typedef list<string> roster;
typedef stack<string> plates;
int main(int argc, const char * argv[]) {
const int SIZE = 10;
//1)
pair<string, int> Values[] =
{
{ "Stewie", 100 }, { "Brian", 90 }, { "Meg", 66 },
{ "Lois", 89 }, { "Chris", 17 }, { "Peter", 21 }, { "Marge", 77 }, { "Bart", 62 }, { "Lisa", 99 },{ "Maggie", 3 }
};
//2))
vector<int> scores;
vector<string> names;
for (int i =0;i < SIZE; i++){
names.push_back(Values[i].first);
scores.push_back((Values[i].second));
}
//3)
for(int i = 0 ;i < scores.size();i++){
cout << names[i] <<" got "<< scores[i]<<endl;
//pairs.insert(names[i], scores[i]);
}
scorecard scard;
int index = 0;
for (scorecard::const_iterator iter = scard.begin();
iter != scard.end();++iter){
scard.insert(std::make_pair(Values[index].first,Values[index].second));
++index;
}
//4) scard is the map and roster is the list
roster r;
for (scorecard::const_iterator iter = scard.begin();iter !=scard.end();++iter){
r.push_back(iter->first);
}
//5
sort(r.begin(),r.end());
//6
plates n;
for (roster::const_iterator iter = r.begin(); iter !=r.end();++iter){
n.push(*iter);
}
//7
while (!n.empty()) {
cout << n.top()<< endl;
n.pop();
}
return 0;
}
|