思路
强行模拟求
#include
#include
using namespace std;
int a[30][30],c[30][30],f[30][30];
char ch[4];
int main()
{
int n;
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%s",&ch);
for (int j=1;j<=n;j++)
{
if (ch[j-1]=='1') a[i][j]=1;
}
}
for (int k=1;k<=4;k++)
{
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
c[i][j]=0;
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
{
if (a[i][j]==1)
{
f[i][j]=a[i][j];
}
c[j][n-i+1]=a[i][j];
}
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
a[i][j]=c[i][j];
int ans=0;
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
{
if (f[i][j]==1) ans++;
}
printf("%d\n",ans);
}
}
Comments NOTHING