选择排序
冒泡排序
插入排序
归并排序
快速排序
二分查找
五子棋
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#define BLANK 0
#define BLACK 1
#define WHITE -1
#define ROW 15
#define COL 15int main()
{int chess[ROW][COL] = {BLANK};int loc_i, loc_j = 0;int player = BLACK;int winner;do{system("cls");//draw a chess boardprintf(" ");for (int i = 0; i < COL; i++){printf("%3d", i);}printf("\n");for (int i = 0; i < ROW; i++){printf("%2d", i);printf("\033[47;31m");for (int j = 0; j < COL; j++){if (chess[i][j] == BLANK)printf("|__");else if (chess[i][j] == BLACK)printf("| *");elseprintf("| o");}printf("|\033[0m\n");}// judge whether to terminatefor(int i=0;i<ROW;i++){for(int j=0;j<COL;j++){if(chess[i][j]==BLANK) continue;if((j<COL-4 && chess[i][j]==chess[i][j+1] && chess[i][j]==chess[i][j+2] && chess[i][j]==chess[i][j+3] && chess[i][j]==chess[i][j+4]) ||(i<ROW-4 && chess[i][j]==chess[i+1][j] && chess[i][j]==chess[i+2][j] && chess[i][j]==chess[i+3][j] && chess[i][j]==chess[i+4][j]) ||(i<ROW-4 && j>4 && chess[i][j]==chess[i+1][j-1] && chess[i][j]==chess[i+2][j-2] && chess[i][j]==chess[i+3][j-3] && chess[i][j]==chess[i+4][j-4]) ||(i<ROW-4 && j<COL-4 && chess[i][j]==chess[i+1][j+1] && chess[i][j]==chess[i+2][j+2] && chess[i][j]==chess[i+3][j+3] && chess[i][j]==chess[i+4][j+4])){winner=player;goto L;}}}// player insert loc_i, loc_jprintf("Player %d! Please enter your move!\n", player);scanf("%d %d", &loc_i, &loc_j);while(chess[loc_i][loc_j]!=BLANK){printf("Invalid location!Enter again!\n");scanf("%d %d", &loc_i, &loc_j);}chess[loc_i][loc_j] = player;// switch the playerplayer = player*-1;} while (loc_i != -1 && loc_j != -1);L:printf("Player %d wins!",winner);return 0;
}