Pagini recente » Cod sursa (job #1103903) | Cod sursa (job #1839988) | Cod sursa (job #556700) | Cod sursa (job #2705001) | Cod sursa (job #363621)
Cod sursa(job #363621)
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int n; //nr de linii matrice patratica;
ifstream file;
file.open("royfloyd.in");
file >> n;
/*ofstream out;
out.open("royfloyd.out");*/
int mat[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
file >> mat[i][j];
if ((mat[i][j] == 0) && (i != j))
mat[i][j] = 1001;
}
/*for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
out << mat[i][j];*/
file.close();
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (mat[i][j] > mat[i][k] + mat[k][j])
mat[i][j] = mat[i][k] + mat[k][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (mat[i][j] == 1001)
mat[i][j] = 0;
}
ofstream out;
out.open("royfloyd.out");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
out << mat[i][j] << " ";
out << endl;
}
out.close();
}