Pagini recente » Cod sursa (job #1918743) | Cod sursa (job #1535184) | Cod sursa (job #1314926) | Cod sursa (job #2424445) | Cod sursa (job #1741641)
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 short[][] v = new short [105][105];
static short n;
public static void read(){
try{
BufferedReader bf = new BufferedReader(new FileReader("royfloyd.in"));
String tmp[] = bf.readLine().split(" ");
n = Short.parseShort(tmp[0]);
for (int i = 0; i < n; ++i){
tmp = bf.readLine().split(" ");
for (int j = 0; j < n; ++j)
v[i][j] = Short.parseShort(tmp[j]);
}
bf.close();
}catch(IOException e){
System.out.println("dunno...prolly no file");
}
}
public static void royfloyd(){
for (short k = 0; k < n; ++k)
for (short i = 0; i < n; ++i)
for (short 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] = (short) (v[i][k] + v[k][j]);
}
public static void write(){
try{
OutputStream fout = new BufferedOutputStream (new FileOutputStream("royfloyd.out"));
for (short i = 0; i < n; ++i){
for (short 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();
}
}