Here is my code for question GOSSIPER, and i'm getting runtime error (SIGSEGV).
Can someone please tell me why.
Thankyou!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n, m, i, j, k, f1, f2, l, c;
char n1[100], n2[100];
while (1) {
scanf("%d%d", &n, &m);
if (n == 0 && m == 0) {
break;
}
char name[n][100];
int g[n][n];
int count[n];
for (i = 0; i < n; i++) {
fflush(stdin);
scanf("%s", name[i]);
for (j = 0; j < n; j++) {
g[i][j] = 0;
}
g[i][i] = 1;
count[n] = 1;
}
for (i = 0; i < m; i++) {
fflush(stdin);
f1 = 0;
f2 = 0;
scanf("%s %s", n1, n2);
for (j = 0; j < n; j++) {
if (strcmp(n1, name[j]) == 0) {
k = j;
f1 = 1;
} else if (strcmp(n2, name[j]) == 0) {
l = j;
f2 = 1;
} else if (f1 == 1 && f2 == 1) {
break;
}
}
c = 0;
for (j = 0; j < n; j++) {
if (g[k][j] == 1 || g[l][j] == 1) {
g[k][j] = 1;
g[l][j] = 1;
c++;
}
}
count[k] = c;
count[l] = c;
}
f1 = 1;
for (i = 0; i < n; i++) {
if (count[i] < n) {
f1 = 0;
break;
}
}
if (f1 == 1) {
printf("YES\n");
} else {
printf("NO\n");
}
}
system("pause");
return 0;
}
created
last reply
- 1
reply
- 131
views
- 2
users