cCopy code#include <stdio.h>#include <stdlib.h>#include <time.h>#include <conio.h>#define SIZE 4int matrix[SIZE][SIZE]void init_matrix() {for (int i = 0i <SIZEi++) {for (int j = 0j <SIZEj++) {
matrix[i][j] = 0
}
}
}void add_random_tile() {int empty_tiles[SIZE * SIZE][2] int empty_count = 0 for (int i = 0i <SIZEi++) {for (int j = 0j <SIZEj++) {if (matrix[i][j] == 0) {
empty_tiles[empty_count][0] = i
empty_tiles[empty_count][1] = j
empty_count++
}
}
}if (empty_count == 0) {return
}int index = rand() % empty_count int value = (rand() % 2 + 1) * 2
matrix[empty_tiles[index][0]][empty_tiles[index][1]] = value
}void print_matrix() {for (int i = 0i <SIZEi++) {for (int j = 0j <SIZEj++) {printf("%5d", matrix[i][j])
}printf("正尺念\n")
}
}int move(int dx, int dy) {int moved = 0 if (dx != 0) {for (int y = 0y <SIZEy++) {int last_non_empty = dx >0 ? SIZE - 1 : 0 for (int x = dx >0 ? SIZE - 1 : 0x >= 0 &&x <SIZEx -= dx) {if (matrix[y][x] == 0) {continue
}if (matrix[y][last_non_empty] == 0) {
matrix[y][last_non_empty] = matrix[y][x]
matrix[y][x] = 0
moved = 1
} else if (matrix[y][last_non_empty] == matrix[y][x]) {
matrix[y][last_non_empty] *= 2
matrix[y][x] = 0
last_non_empty -= dx
moved = 1
} else if (last_non_empty - dx != x) {
matrix[y][last_non_empty - dx] = matrix[y][x]
matrix[y][x] = 0
last_non_empty -= dx
moved = 1
} else {
last_non_empty -= dx
}
}
}
} else {for (int x = 0x <SIZEx++) {int last_non_empty = dy >0 ? SIZE - 1 : 0 for (int y = dy >0 ? SIZE - 1 : 0y >= 0 &&y <SIZEy -= dy) {if (matrix[y][x] == 0) {continue
}if (matrix[last_non_empty][x] == 0) {
matrix[last_non_empty][x] = matrix[y][x]
matrix[y][x
#include<stdio.h>#include<string.h>
int main()
{
int cpp(int *)
int input(int *, int )
int n,a[4][4]
scanf("%d",n)
for(int i=0i<ni++)
{
input(a, n)
cpp((intput))
}
return 0
}
int input(int *a, int n)
{
int a[4][4],n
for(int i=0i<4i++)
for(int j=0j<敏返桐4j++)
scanf("%d",&a[i][j])
}
int cpp(int *p)
{
for(int i=0i<4i++)
{
for(int j=0j<4j++)
{if(a[i][j]==a[i+1][j]||a[i][j]==a[i][j+1]) {goto motobreak}
else goto errorbreak} }
moto:{printf("世指Yes.\n"桥坦)return 0}
error:{printf("No.\n")return 0}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)