Pagini recente » Cod sursa (job #205455) | Cod sursa (job #1663370) | Cod sursa (job #594497) | Cod sursa (job #1057695) | Cod sursa (job #1750819)
#include <fstream>
#define MAX_DIM 101
using namespace std;
void ReadInput(int cost[][MAX_DIM], int* n);
void WriteResult(int cost[][MAX_DIM], int n);
void RoyFloyd(int cost[][MAX_DIM], int n);
int main()
{
int cost[MAX_DIM][MAX_DIM];
int n;
ReadInput(cost, &n);
RoyFloyd(cost, n);
WriteResult(cost, n);
return 0;
}
void ReadInput(int cost[][MAX_DIM], int* n)
{
ifstream fin;
fin.open("royfloyd.in");
fin >> *n;
for(int i = 0; i < *n; ++i)
for(int j = 0; j < *n; ++j)
fin >> cost[i][j];
fin.close();
}
void RoyFloyd(int cost[][MAX_DIM], int n)
{
for(int k = 0; k < n; k++)
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(cost[i][j] > cost[i][k] + cost[k][j])
cost[i][j] = cost[i][k] + cost[k][j];
}
void WriteResult(int cost[][MAX_DIM], int n)
{
ofstream fout;
fout.open("royfloyd.out");
for(int i = 0; i < n; ++i)
{
for(int j = 0; j < n; ++j)
fout << cost[i][j] << " ";
fout << "\n";
}
}