Pagini recente » Cod sursa (job #1533172) | Cod sursa (job #2332367) | Cod sursa (job #559858) | Cod sursa (job #1351672) | Cod sursa (job #2368617)
#include <iostream>
#include <fstream>
std::ifstream in("royfloyd.in");
const int Nmax = 101;
void EmptyDArray(int connections[][Nmax], int n)
{
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
connections[i][j] = 0;
}
void Citire(int connections[][Nmax], int n)
{
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
in >> connections[i][j];
in.close();
}
void RoyFloyd(int connections[][Nmax], int n)
{
for(int k = 0; k < n; k++)
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if (connections[i][k] &&
connections[k][j] &&
(connections[i][k] + connections[k][j] < connections[i][j] || !connections[i][j])
&& i != j)
{
connections[i][j] = connections[i][k] + connections[k][j];
}
}
void Print(int connections[][Nmax], int n)
{
std::ofstream out("royfloyd.out");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
out << connections[i][j] << " ";
out << '\n';
}
}
int main()
{
int connections[Nmax][Nmax];
int n;
in >> n;
EmptyDArray(connections, n);
Citire(connections, n);
RoyFloyd(connections,n);
Print(connections, n);
}