blob: d0a0f8c3a7d5ae999bb0d3edb4a13554d63ba1ec (
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
65
66
67
68
69
70
71
|
/**
* @file compare_histo.cpp
*
* $Id$
*
*/
#include <utility>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <map>
typedef std::map<long,double> Vector;
typedef std::pair<long,double> Element;
std::ostream &
operator<< (std::ostream &os,
const Vector::value_type &p)
{
return os << p.first << " " << p.second;
}
void
load_file (Vector &vector,
const char *filename)
{
std::ifstream is (filename);
if (!is)
throw "Cannot open file";
while (is && !is.eof ())
{
long i; double v;
is >> i >> v;
Vector::value_type e (i, v);
vector.insert (e);
}
}
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
Vector X;
load_file (X, argv[1]);
Vector Y;
load_file (Y, argv[2]);
Vector Z;
for (Vector::iterator i = X.begin (); i != X.end (); ++i) {
for (Vector::iterator j = Y.begin (); j != Y.end (); ++j) {
long ki = (*i).first - (*j).first;
double p = (*i).second * (*j).second;
Vector::iterator k = Z.find (ki);
if (k == Z.end ())
Z.insert (Element (ki, p));
else
Z[ki] += p;
}
}
for (Vector::iterator i = Z.begin (); i != Z.end (); ++i)
{
std::cout << (*i) << "\n";
}
return 0;
}
|