编程新手求解,请大神指点
#include<stdio.h>main()
{
int a[4][4],b[4],i,j,k,l;
char c[4];
for (i=1;i<=4;i++)
{
for (j=1;j<=4;j++)
{
scanf ("%d",&a[i][j]);
}
}
scanf("\n");
for (i=1;i<=3;i++)
scanf ("%c ",&c[i]);
scanf("%c",&c[4]);
scanf("\n");
for (j=1;j<=4;j++)
scanf ("%d",&b[i]);
for (l=1;l<=4;l++)
{
if (c[l]=='a')
{
for (i=1;i<=4;i++)
{
for (j=1;j<=4;j++)
{
if (a[i][j]==0)
{
for (k=j;k<=4;k++)
{
if (a[i][k]!=0)
{
a[i][j]=a[i][k];
a[i][k]=0;
}
break;
}
}
}
for (j=1;j<=3;j++)
{
if (a[i][j]==0)
break;
else if (a[i][j]==a[i][j+1])
{
a[i][j]=a[i][j]+a[i][j+1];
a[i][j+1]=0;
for (k=j+1;k<=3;k++)
{
a[i][k]=a[i][k+1];
a[i][4]=0;
}
}
}
}
}
else if (c[l]=='d')
{
for (i=1;i<=4;i++)
{
for (j=4;j>=1;j--)
{
if (a[i][j]==0)
{
for (k=j;k>=1;k--)
{
if (a[i][k]!=0)
{
a[i][j]=a[i][k];
a[i][k]=0;
}
break;
}
}
}
for (j=4;j>=1;j--)
{
if (a[i][j]==0)
break;
else if (a[i][j]==a[i][j-1])
{
a[i][j]=a[i][j]+a[i][j-1];
a[i][j-1]=0;
for (k=j-1;k>=1;k--)
{
a[i][k]=a[i][k-1];
a[i][1]=0;
}
}
}
}
}
else if (c[l]=='w')
{
for (j=1;j<=4;j++)
{
for (i=1;i<=4;i++)
{
if (a[i][j]==0)
{
for (k=i;k<=4;i++)
{
if (a[k][j]!=0)
{
a[i][j]=a[k][j];
a[k][j]=0;
}
break;
}
}
}
for (i=1;i<=3;i++)
{
if (a[i][j]==0)
break;
else if (a[i][j]==a[i+1][j])
{
a[i][j]=a[i][j]+a[i+1][j];
a[i+1][j]=0;
for (k=i+1;k<=3;k++)
{
a[k][j]=a[k+1][j];
a[4][j]=0;
}
}
}
}
}
else if (c[l]=='s')
{
for (j=1;j<=4;j++)
{
for (i=4;i>=1;i--)
{
if (a[i][j]==0)
{
for (k=i;k>=1;k--)
{
if (a[k][j]!=0)
{
a[i][j]=a[k][j];
a[k][j]=0;
}
break;
}
}
}
for (i=4;i>=1;i--)
{
if (a[i][j]==0)
break;
else if (a[i][j]==a[i-1][j])
{
a[i][j]=a[i][j]+a[i-1][j];
a[i-1][j]=0;
for (k=i-1;k>=1;k--)
{
a[k][j]=a[k-1][j];
a[1][j]=0;
}
}
}
}
}
i=b[l]/4+1;
j=b[l]%4;
while (a[i][j]!=0)
{
b[l]=b[l]+1;
i=b[l]/4+1;
j=b[l]%4;
}
if (j==4)
a[i][j]=4;
else
a[i][j]=2;
}
for (i=1;i<=4;i++)
{
for (j=1;j<=4;j++)
{
if (i==4&&j==4)
printf ("%d\n",a[i][j]);
else
printf ("%d ",a[i][j]);
}
}
system ("pause");
}