Pagini recente » Urmasii lui Moisil 2016, Clasa a 10-a | Istoria paginii utilizator/cosminroman07 | Cod sursa (job #2004259) | Cod sursa (job #396937) | Cod sursa (job #1741640)
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
public class Main {
static int[][] v = new int [105][105];
static int n;
public static void read(){
try{
BufferedReader bf = new BufferedReader(new FileReader("royfloyd.in"));
String tmp[] = bf.readLine().split(" ");
n = Integer.parseInt(tmp[0]);
for (int i = 0; i < n; ++i){
tmp = bf.readLine().split(" ");
for (int j = 0; j < n; ++j)
v[i][j] = Integer.parseInt(tmp[j]);
}
bf.close();
}catch(IOException e){
System.out.println("dunno...prolly no file");
}
}
public static void royfloyd(){
for (int k = 0; k < n; ++k)
for (int i = 0; i < n; ++i)
for (int j = 0 ; j < n; ++j)
if (v[i][k] > 0 && v[k][j] > 0 && (v[i][j] > v[i][k] + v[k][j] || v[i][j] == 0) && i != j)
v[i][j] = v[i][k] + v[k][j];
}
public static void write(){
try{
OutputStream fout = new BufferedOutputStream (new FileOutputStream("royfloyd.out"));
for (int i = 0; i < n; ++i){
for (int j = 0; j < n; ++j)
fout.write((v[i][j] + " ").getBytes());
fout.write(("\r\n").getBytes());
}
fout.close();
}catch(Exception ex){
System.out.println("Had to write this shit again cuz i deleted it first time");
}
}
public static void main(String[] args){
read();
royfloyd();
write();
}
}