我在进行编程练习时遇到expected declaration or statement at end of input
错误
http://www.patest.cn/contests/mooc-ds2015spring/06-%E5%9B%BE2
这是我的代码:
#include <stdio.h>
#include <malloc.h>
#include <math.h>
typedef struct Node {
int x;
int y;
} Position;
int result;
Position beast[1000];
int visited[1000];
int NumOfB, JumpAb;
void dfs(int i) {
int j;
if (Available(i)) {
visited[i] = 1;
if (Save(i)) {
result = 1;
printf("Yes");
}
for(j = 0; j < NumOfB; j++)
if (!visited[j])
dfs(j);
}
int Available(int i) {
int j;
double d_x, d_y;
for (j = 0; j < NumOfB; j++) {
d_x = beast[i].x - beast[j].x;
d_y = beast[i].y - beast[j].y;
if ((d_x * d_x + d_y * d_y) < JumpAb * JumpAb && visited[j] == 1)
return 1;
}
return 0;
}
int Save(int i) {
if ((abs(50 - abs(beast[i].x)) < JumpAb) || ((abs(50 - abs(beast[i].y))) < JumpAb))
return 1;
else
return 0;
}
int FirstJump(int i) {
if ((beast[i].x * beast[i].x + beast[i].y * beast[i].y) < JumpAb * JumpAb) {
return 1;
} else {
return 0;
}
}
int main() {
result = 0;
scanf("%d %d", &NumOfB, &JumpAb);
int i;
Position *p = NULL;
for (i = 0; i < NumOfB; i++) {
p = (Position*)malloc(sizeof(Position));
scanf("%d %d", &p->x, &p->y);
}
for (i = 0; i < NumOfB; i++) {
visited[i] = 0;
// if ((beast[i].x * beast[i].x + beast[i].y * beast[i].y) < JumpAb * JumpQAb)
// visited[i] = 1;
}
for(i = 0; i < NumOfB; i++) {
if (!visited[i] && FirstJump(i)) {
visited[i] = 1;
dfs(i);
}
}
if (result == 0) {
printf("No");
}
return 0;
}
我找不到上述功能的任何错误。请帮我理解这个错误。
答案 0 :(得分:3)
您在本节中缺少一个大括号:
if (Available(i)){
visited[i]=1;
if (Save(i)) {
result = 1;
printf("Yes");
}