Yurttas/PL/OOL/Cplusplus/F/07/03/01/map 00.cpp
Jump to navigation
Jump to search
1/*
2 Copyright(C) 2000
3 All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4
5 Permission to use, copy, modify, and distribute this
6 software and its documentation for EDUCATIONAL purposes
7 and without fee is hereby granted provided that this
8 copyright notice appears in all copies.
9
10 date : January 1, 2000.
11 author : Salih Yurttas.
12
13 map_00.cpp
14*/
15
16
17#include <iostream>
18
19#include <vector>
20#include <string>
21
22#include <map>
23
24using namespace std;
25
26int main(int argc, char* argv[]) {
27
28 string fruits[] = {"strawberry",
29 "plum",
30 "apple",
31 "orange",
32 "apricot",
33 "peach",
34 "mango",
35 "watermelon"};
36
37 vector<string> fruits_list(fruits, fruits+8);
38
39 int counts[] = {4,
40 2,
41 1,
42 8,
43 5,
44 6,
45 7,
46 3};
47
48 vector<int> counts_list(counts, counts+8);
49
50 map<int, string, less<int> > counts_fruits_list;
51
52 int n = counts_list.size();
53 for(int i=0; i<n; ++i)
54 counts_fruits_list[counts_list.at(i)] = fruits_list.at(i);
55
56 map<int, string, less<int> >::const_iterator i = counts_fruits_list.begin();
57 map<int, string, less<int> >::const_iterator k = counts_fruits_list.end();
58
59 for(; i!=k; ++i)
60 cout << i->first << " - " << i->second << endl;
61
62}