Professional Documents
Culture Documents
Tema 4
Tema 4
Tema 4
#include <vector>
#include <iostream>
#define MAX_CURRENCIES 50
#define INF 1e9
class CurrencyConverter {
public:
CurrencyConverter() {
//initialize all distance to INF (infinity)
for (int i = 0; i < MAX_CURRENCIES; i++)
for (int k = 0; k < MAX_CURRENCIES; k++)
distance[i][k] = (i == k) ? 1 : INF;
}
floydWarshall();
if (distance[i][j] == INF) {
return 0;
}
else {
return distance[i][j];
}
}
private:
std::unordered_map<std::string, int> currency_map;
double distance[MAX_CURRENCIES][MAX_CURRENCIES];
int current_index = 0;
void floydWarshall() {
for (int k = 0; k < current_index; k++) {
for (int i = 0; i < current_index; i++) {
for (int j = 0; j < current_index; j++) {
distance[i][j] = std::min(distance[i][j], distance[i][k] *
distance[k][j]);
}
}
}
}
};