注意的点是用两个矩阵存放所有房间的状况,每天的传染是只能传染一次的。
#include <iostream>
#include <string.h>
#include <stack>
#include <stdio.h>
using namespace std;
int a[105][105];
int b[105][105];
stack <int> s;
int main()
{
int n;
cin >> n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
char c;
cin >> c;
switch (c)
{
case '.':
b[i][j]=a[i][j]=1;
break;
case '#':
b[i][j]=a[i][j]=0;
break;
case '@':
b[i][j]=a[i][j]=-1;
break;
}
}
int m;
cin >> m;
for(int day=2;day<=m;day++)
{
for(int i=0;i<n;i++)
for(int j=0;j