Pagini recente » Cod sursa (job #904182) | Cod sursa (job #2735534) | Cod sursa (job #1761083) | Cod sursa (job #2692850) | Cod sursa (job #1077427)
# include <cstdio>
# include <queue>
using namespace std;
const int N = 100, MAX = 1000 ,L = MAX * N + N - 1;
int a [N + 1] [N + 1];
queue <int> q;
char s [L];
int n;
bool digit (char c)
{
if ('0' <= c && c <= '9')
return true;
return false;
}
void citeste ()
{
int i, j, k;
scanf ("%d\n", & n);
for (i = 1; i <= n; i ++)
{
gets (s);
k = 1;
for (j = 0; s [j] != NULL; j ++)
if (digit (s [j]))
a [i] [k] = a [i] [k] * 10 + s [j] - '0';
else
k ++;
}
}
void init ()
{
freopen ("royfloyd.in", "r", stdin);
freopen ("royfloyd.out", "w", stdout);
citeste ();
}
void royFloyd ()
{
int i, j, aux;
for (i = 1; i <= n; i ++)
{
q. push (i);
while (q. size ())
{
aux = q. front ();
for (j = 1; j <= n; j ++)
if (j != i && a [aux] [j])
if (a [i] [j] == 0 || a [aux] [j] + a [i] [aux] <= a [i] [j])
{
q. push (j);
a [i] [j] = a [aux] [j] + a [i] [aux];
}
q. pop ();
}
}
}
void afisare ()
{
int i, j;
for (i = 1; i <= n; i ++)
{
for (j = 1; j <= n; j ++)
printf ("%d ", a [i] [j]);
printf ("\n");
}
}
int main ()
{
init ();
royFloyd ();
afisare ();
return 0;
}