#include <iostream>
#include <queue>
using namespace std;
char a[22][22];
int turn[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
typedef struct m
{
int x, y;
} ob;
int main()
{
int w, h;
while (cin >> w >> h)
{
ob st;
for (int i = 1; i <= h; i++)
{
getchar();
for (int j = 1; j <= w; j++)
{
cin >> a[i][j];
if (a[i][j] == '@')
{
st.x = j, st.y = i;
}
}
}
int sum = 1;
queue<ob> line;
line.push(st);
a[line.front().y][line.front().x] = 0;
do
{
for (int i = 0; i < 4; i++)
{
if (a[line.front().y + turn[i][1]][line.front().x + turn[i][0]] == '.')
{
line.push({line.front().x + turn[i][0], line.front().y + turn[i][1]});
a[line.front().y + turn[i][1]][line.front().x + turn[i][0]] = 0;
sum++;
}
}
line.pop();
} while (line.size());
cout << sum<<endl;
}
return 0;
}
附上oj信息:
Compile Error
Main.cpp
F:\temp\23176735.14851\Main.cpp(40) : error C2143: syntax error : missing ')' before '{'
F:\temp\23176735.14851\Main.cpp(40) : error C2660: 'std::queue<_Ty>::push' : function does not take 0 arguments
with
[
_Ty=ob
]
F:\temp\23176735.14851\Main.cpp(40) : error C2143: syntax error : missing ';' before '{'
F:\temp\23176735.14851\Main.cpp(40) : error C2143: syntax error : missing ';' before '}'
F:\temp\23176735.14851\Main.cpp(40) : error C2059: syntax error : ')'