summaryrefslogtreecommitdiff
path: root/Year_2/Algorithms/hash-chain-div.cc
blob: cac5c2c93c770bc236cab9d66ea3a8ddfb627d72 (plain)
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
#include <fstream>
#include <iostream>

using namespace std;

int
main(int argc, char** argv)
{
    int n = (argc > 1) ? atoi(argv[1]) : 100;
    unsigned i, j, bucketsize, bucketnum;
    string t;

    ifstream fin("input.txt");
    ofstream fout("output.txt");

    for (i = 0; i < n; ++i) {
        fin >> t >> bucketsize >> bucketnum;

        int* h = new int[bucketsize];
        for (j = 0; j < bucketsize; ++j)
            h[j] = 0;

        if (t == "int") {
            int k;

            for (j = 0; j < bucketnum; ++j) {
                fin >> k;
                h[k % bucketsize]++;
            }
        } else if (t == "double") {
            double k;

            for (j = 0; j < bucketnum; ++j) {
                fin >> k;
                h[static_cast<int>(k) % bucketsize]++;
            }
        } else if (t == "char") {
            char k;

            for (j = 0; j < bucketnum; ++j) {
                fin >> k;
                h[static_cast<int>(k) % bucketsize]++;
            }
        } else if (t == "bool") {
            bool k;

            for (j = 0; j < bucketnum; ++j) {
                fin >> k;
                h[static_cast<int>(k) % bucketsize]++;
            }
        }

        for (j = 0; j < bucketsize; ++j)
            fout << h[j] << ' ';

        fout << endl;

        delete[] h;
    }

    fin.close();
    fout.close();
    return 0;
}