Pagini recente » Cod sursa (job #2426399) | Cod sursa (job #2668120) | Cod sursa (job #1024623) | Cod sursa (job #2541965) | Cod sursa (job #363610)
Cod sursa(job #363610)
#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];
/*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];
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();
}