文章
25
粉丝
364
获赞
8
访问
218.9k
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int matrix[4][4];
int operation;
//读取数据
scanf("%d", &operation);
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
scanf("%d", &matrix[i][j]);
}
}
switch (operation)
{
//上
case 1:
for (int j = 0; j < 4; j++)
{
for (int i = 0, k; i < 4; i++)
{
if (matrix[i][j] != 0)
{
int tmp = matrix[i][j];
for (k = i-1; k >= 0; k--) //找到前面第一个非0项
{
if (matrix[k][j] != 0)
{
break;
}
}
matrix[i][j] = 0;
matrix[k + 1][j] = tmp; //移动
...
登录后发布评论
暂无评论,来抢沙发