Pagini recente » Cod sursa (job #2155234) | Cod sursa (job #2146157) | Cod sursa (job #2118344) | Cod sursa (job #2163064) | Cod sursa (job #1435266)
#include <iostream>
#include <fstream>
#define INPUT_FILE "royfloyd.in"
#define OUTPUT_FILE "royfloyd.out"
#define MAX_SIZE 100
std::fstream in(INPUT_FILE, std::fstream::in);
std::fstream out(OUTPUT_FILE, std::fstream::out);
using namespace std;
int main(int argc, char const *argv[])
{
register int i, j, k;
int node_count;
int cost_matrix[MAX_SIZE][MAX_SIZE];
in >> node_count;
for(i = 0; i < node_count; i++) {
for (j = 0; j < node_count; j++) {
in >> cost_matrix[i][j];
}
}
for (i = 0; i < node_count; i++) {
for (j = 0; j < node_count; j++) {
for (k = 0; k < node_count; k++) {
if (cost_matrix[i][j] > cost_matrix[i][k] + cost_matrix[k][j]) {
cost_matrix[i][j] = cost_matrix[i][k] + cost_matrix[k][j];
}
}
}
}
for(i = 0; i < node_count; i++) {
for (j = 0; j < node_count; j++) {
out << cost_matrix[i][j] << " ";
}
out << "\n";
}
out.close();
in.close();
return 0;
}