Pagini recente » Cod sursa (job #2622495) | Cod sursa (job #2448746) | Cod sursa (job #2989791) | Cod sursa (job #2515092) | Cod sursa (job #2336806)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("royfloyd.in");
ofstream g ("royfloyd.out");
int n;
short mat[101][101];
void citire();
void royfloyd() {
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
if (!(i == j)) {
for(int k = 1; k <= n; ++k) {
if (mat[i][j] > mat[i][k] + mat[k][j] &&
i != k && k != j) {
mat[i][j] = mat[i][k] + mat[k][j];
}
}
}
}
}
}
void afisare() {
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
g << mat[i][j] << ' ';
}
g << '\n';
}
}
int main()
{
citire();
royfloyd();
afisare();
return 0;
}
void citire() {
f >> n;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
f >> mat[i][j];
}
}
}