i submitted 423 agin and agin and evrything seems ok except the judges response(offcourse i don't want to say that the judge is wrong) ...but i get all the time runtime error. can anyone help me.....
at first i thought the problem may be regarding the qsort function, so i change i, but no change....bellow in the code i commented the previous qsort portion...
here is my code:
[c]
/*@BEGIN_OF_SOURCE_CODE*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int adj[200][200];
int sort_function( const void *a, const void *b);
struct table
{
int known;
int dist;
int path;
} t[200];
void main()
{
int i, j, k, n, start = 1;
char str[205], *p;
while(scanf("%d\n", &n) == 1)
{
memset(adj, 0, sizeof(adj));
for(i = 0; i < n-1; i++)
{
j = 0;
strcpy(str, "");
gets(str);
p = strtok(str, " ""\t");
if(p)
if(!strcmp(p, "x"))
k = 0;
else
k = atoi(p);
adj[i+1][j] = k;
adj[j][i+1] = k;
for(;;)
{
p = strtok(NULL, " \t");
if(p)
{
if(!strcmp(p, "x"))
k = 0;
else
k = atoi(p);
}
else
break;
j++;
adj[i+1][j] = k;
adj[j][i+1] = k;
}
}
for(i = 0; i < n; i++)
{
t
.known = 0;
t.dist = 9999;
t.path = 0;
}
t[start-1].dist = 0;
int min = 10000, flag = 0, v;
for(;;)
{
flag = 0;
min = 10000;
for(i = 0; i < n; i++)
if(!t.known)
{
if(t.dist < min)
{
min = t.dist;
v = i;
}
flag = 1;
}
if(!flag)
break;
t[v].known = 1;
for(j = 0; j < n; j++)
if(adj[v][j])
if(!t[j].known)
if((t[v].dist + adj[v][j]) < t[j].dist)
{
t[j].dist = t[v].dist + adj[v][j];
t[j].path = v+1;
}
}
// qsort(t, n, sizeof(t[0]), sort_function);
int max = 0;
for(i = 0; i < n; i++)
if(t.dist > max)
max = t.dist;
printf("%d\n", max);
// printf("%d\n", t[0].dist);
}
}
int sort_function( const void *a, const void *b)
{
struct table aa, bb;
aa = *(struct table *)a;
bb = *(struct table *)b;
if(aa.dist < bb.dist)
return 1;
if(aa.dist > bb.dist)
return -1;
else
return 1;
}
/*@END_OF_SOURCE_CODE*/
[/c]
thanx in advance.