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
|
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cmath>
using namespace std;
#define N 69
#define M 10
int argmin(int x[]) {
int i;
int min = x[0], argmin=0;
for (i=0; i<N; i++)
if (min > x[i]) {
min = x[i];
argmin = i;
}
return argmin;
}
int manhattan(int x[], int y[]) {
int i, s = 0;
for (i=0; i<M; i++)
s += abs(x[i]-y[i]);
return s;
}
int main() {
int d[N];
int p[N][M];
int i, j;
string initial;
ifstream infile;
infile.open("neo-ffi.dat");
if (infile) {
for (i=0; i<N; i++) {
infile >> initial;
for (j=0; j<M; j++)
infile >> p[i][j];
}} else {
cout << "File could not be opened!";
exit(1);
}
int me[M] = {5,3,4,3,1,4,1,3,4,2};
int you[M];
for (i=0; i<N; i++) {
for (j=0; j<M; j++) {
you[i] = p[i][j];
} d[i] = manhattan(me, you);
}
int similar = argmin(d);
for (j=0; j<M; j++) {
cout << p[similar][j] << " ";
} cout << endl;
return 0;
}
|