Yurttas/PL/OOL/Cplusplus/F/07/03/01/mmap 11.cpp

From ZCubes Wiki
Jump to navigation Jump to search
 1/*
 2   Copyright(C) 2008
 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   : December 1, 2008.
11   author : Salih Yurttas.
12
13   mmap_11.cpp
14*/
15
16#include "stdafx.h"
17
18using namespace System;
19
20#include <iostream>
21
22#include <vector>
23#include <string>
24
25#include <map>
26
27using namespace std;
28
29int main(array<System::String ^> ^args)
30{
31  string fruits[] = {"strawberry",
32                     "plum",
33                     "apple",
34                     "orange",
35                     "apricot",
36                     "peach",
37                     "mango",
38                     "watermelon"};
39
40  vector<string> fruits_list(fruits, fruits+8);
41
42  int counts[] = {4,
43                  4,
44                  1,
45                  8,
46                  1,
47                  1,
48                  7,
49                  3};
50
51  vector<int> counts_list(counts, counts+8);
52
53  multimap<int, string, less<int> > counts_fruits_list;
54
55  int n = counts_list.size();
56  for(int i=0; i<n; ++i)
57    counts_fruits_list.insert(pair<int,string>(counts_list.at(i),fruits_list.at(i)));
58
59  multimap<int, string, less<int> >::const_iterator i = counts_fruits_list.begin();
60  multimap<int, string, less<int> >::const_iterator k = counts_fruits_list.end();
61
62  for(; i!=k; ++i)
63    cout << i->first << " - " << i->second << endl;
64
65  return 0;
66}