diff --git "a/AI\344\272\224\345\255\220\346\243\213\345\256\236\351\252\214\346\212\245\345\221\212.docx" "b/AI\344\272\224\345\255\220\346\243\213\345\256\236\351\252\214\346\212\245\345\221\212.docx" new file mode 100644 index 0000000..dba53d0 Binary files /dev/null and "b/AI\344\272\224\345\255\220\346\243\213\345\256\236\351\252\214\346\212\245\345\221\212.docx" differ diff --git a/aigo.c b/aigo.c new file mode 100644 index 0000000..c3915ed --- /dev/null +++ b/aigo.c @@ -0,0 +1,533 @@ +#include "raylib.h" +#include +#include "stack.h" +#include +#include +enum chessboard{ + Space=0,black=-1,white=1 +}; +void drawChessboard(int n,double len,int **map) { + for(int i=1;i<=n;i++) { + DrawLine(len*i, len, len*i, n*len, BLACK); + } + for(int j=1;j<=n;j++){ + DrawLine(len, len*j, n*len, len*j, BLACK); + } + DrawCircle(len*(n+1)/2,len*(n+1)/2,len/8,BLACK); + DrawCircle(len*(n+5)/4,len*(n+5)/4,len/8,BLACK); + DrawCircle(len*((n+5)/4+6),len*((n+5)/4+6),len/8,BLACK); + DrawCircle(len*(n+5)/4,len*((n+5)/4+6),len/8,BLACK); + DrawCircle(len*((n+5)/4+6),len*(n+5)/4,len/8,BLACK); + for(int i=0;i 25 + i * 50 && pos.x < 75 + i * 50 && pos.y > 25 + j * 50 && pos.y < 75 + j * + 50) { + map[i][j] = Space; + return 1;// + } + } + } + } + return 0; +} +_Bool isWiningwhite(int **map,int n) { + int map2[n+1][n+1]; + int gameover=1; + for(int i=0;i5) return 20000; + if(self==5&&enemy==0) return 20000; + if(self==5&&enemy==1) return 20000; + if(self==5&&enemy==2) return 20000; + if(self==4&&enemy==0) return 5000; + if(self==4&&enemy==1) return 300; + if(self==4&&enemy==2) return 100; + if(self==3&&enemy==0) return 300; + if(self==3&&enemy==1) return 100; + if(self==3&&enemy==2) return 50; + if(self==2&&enemy==0) return 50; + if(self==2&&enemy==1) return 20; + if(self==2&&enemy==2) return 10; + if(self==1&&enemy==0) return 10; + if(self==1&&enemy==1) return 5; + if(self==1&&enemy==2) return 3; +}//分数表 +int goBang_getHorizontalScore(int **map,int r,int c,int color){ + //从c向左遍历直到遇到空白,或者其他棋子 + int self=1; + int enemy=0; + for(int i=c-1;i>=0;i--){ + if(c==0){ + enemy++; + }else if(map[r][i]==color){ + self++; + } else if(map[r][i]==0){ + break; + } else{ + enemy++; + break; + } + } + for(int i=c+1;i<15;i++){ + if(c==14){ + enemy++; + }if(map[r][i]==color){ + self++; + } else if(map[r][i]==0){ + break; + } else{ + enemy++; + break; + } + }//右遍历 + return goBang_scoreTable(self, enemy); +}//水平得分情况 +int goBang_getVerticalScore(int **map,int r,int c,int color){ + int self=1; + int enemy=0; + for(int i=r-1;i>=0;i--){ + if(r==0){ + enemy++; + }else if(map[i][c]==color){ + self++; + } else if(map[i][c]==0){ + break; + } else{ + enemy++; + break; + } + } + for(int i=r+1;i<15;i++){ + if(r==14){ + enemy++; + }else if(map[i][c]==color){ + self++; + } else if(map[i][c]==0){ + break; + } else{ + enemy++; + break; + } + } + return goBang_scoreTable(self, enemy); +}//竖直得分情况 +int goBang_getLhtScore(int **map,int r,int c,int color){ + int self=1; + int enemy=0; + for(int i=r+1,k=c-1;i<15&&k>=0;i++,k--){ + if(r==14||c==0){ + enemy++; + }else if(map[i][k]==color){ + self++; + } else if(map[i][k]==0){ + break; + } else{ + enemy++; + break; + } + } + for(int i=r-1,k=c+1;i>=0&&k<15;i--,k++){ + if(r==0||c==14){ + enemy++; + }else if(map[i][k]==color){ + self++; + } else if(map[i][k]==0){ + break; + } else{ + enemy++; + break; + } + } + return goBang_scoreTable(self, enemy); +}//左斜得分情况 +int goBang_getRhtScore(int **map,int r,int c,int color){ + int self=1; + int enemy=0; + for(int i=r+1,k=c+1;i<15&&k<15;i++,k++){ + if(c==14||r==14) { + enemy++; + }else if(map[i][k]==color){ + self++; + } else if(map[i][k]==0){ + break; + } else{ + enemy++; + break; + } + } + for(int i=r-1,k=c-1;i>=0&&k>=0;i--,k--){ + if(c==0||c==0){ + enemy++; + }else if(map[i][k]==color){ + self++; + } else if(map[i][k]==0){ + break; + } else{ + enemy++; + break; + } + } + return goBang_scoreTable(self, enemy); +}//右斜得分情况 +int goBang_getScore(int **map,int r,int c,int color){ + int numH1= goBang_getHorizontalScore(map,r,c,color); + int numV1= goBang_getVerticalScore(map,r,c,color); + int numL1= goBang_getLhtScore(map,r,c,color); + int numR1= goBang_getRhtScore(map,r,c,color); + int xScore=numH1; + int yScore=numV1; + int IScore=numL1; + int RScore=numR1; + return xScore+yScore+IScore+RScore; +}//初版模型,之后会分别计算人和ai的分数 +typedef struct Zuobiao{ + int row; + int col; +}Zuobiao; +typedef struct Chess{ + struct Zuobiao zuobiao; + int score; +}; +struct Chess goBang_CalculateBest(int **map,int color){ + int max=0; + struct Chess zuobiao; + for(int i=0;i<15;i++){ + for(int j=0;j<15;j++){ + if(map[i][j]!=0) continue; + zuobiao.score= goBang_getScore(map,i,j,color); + if(zuobiao.score>=20000) { + zuobiao.zuobiao.row=i; + zuobiao.zuobiao.col=j; + return zuobiao; + } + if(zuobiao.score>max){ + max=zuobiao.score; + zuobiao.zuobiao.row=i; + zuobiao.zuobiao.col=j; + } + } + } + return zuobiao; +} + +bool emptyCells(int**map,int n){ + for(int i=0;i=b?a:b; +} +int MIN(int a,int b){ + return a<=b?a:b; +} +int evaLuate(int **map,int color){ + int levelself=-20000; + int levelenemy=-20000; + int score1; + int score2; + if(!emptyCells(map,15)){ + return 0; + }else{ + for (int i = 0; i < 15; i++) { + for (int j = 0; j < 15; j++) { + if(map[i][j]!=Space&&map[i][j]==color) { + score1 = goBang_getScore(map, i, j, color); + levelself += score1; + }else if(map[i][j]!=Space&&map[i][j]==-color){ + score2= goBang_getScore(map,i,j,-color); + levelenemy+=score2; + } + } + } + } + return levelself-levelenemy; + +} +int EMPTYCELLS(int**map){ + int empty=0; + for(int i=0;i<15;i++){ + for(int j=0;j<15;j++){ + if(map[i][j]==0) + empty++; + } + } + return empty; +}//获取棋盘中空位置的长度 +typedef struct Zuobiao2{ + struct Zuobiao zuobiaoxy[225]; +}; +struct Zuobiao2 Findemptycells(int **map,int color){ + struct Zuobiao2 emptycells; + int k=0;int exchange;struct Zuobiao exchangezuobiao; + int empty= EMPTYCELLS(map); + int score[empty]; + for(int i=0;i<15;i++){ + for(int j=0;j<15;j++){ + if(map[i][j]==Space){ + emptycells.zuobiaoxy[k].row=i; + emptycells.zuobiaoxy[k++].col=j; + } + }if(k==empty) break; + } + for(int m=0;mbestMove.score){ + bestMove=move; + } + //printf(" %d",bestMove.score); + alpha= MAX(alpha,bestMove.score); + if(alpha>=beta){ + //printf("cut"); + break; + } + } + }else{ + bestMove.score=INT_MAX; + struct Zuobiao2 emptycells= Findemptycells(map,-color); + for(int k=0;k<10;k++){ + map[emptycells.zuobiaoxy[k].row][emptycells.zuobiaoxy[k].col]=-color; + + move= alphaBeta(map,alpha,beta,true,depth-1,color); + + map[emptycells.zuobiaoxy[k].row][emptycells.zuobiaoxy[k].col]=Space; + if(move.score=beta){ + //printf("cut"); + break; + } + } + } + return bestMove; +} +struct Zuobiao action(int **map,int color){ + struct Zuobiao Move; + struct Chess bestMove; + if(map[7][7]==Space) { + Move.row = 7; + Move.col = 7; + return Move; + } + int empty= EMPTYCELLS(map); + if(empty==224){ + Move.row=8; + Move.col=7; + return Move; + } + bestMove= alphaBeta(map,INT_MIN,INT_MAX,true,8,color); + return bestMove.zuobiao; +} +struct Zuobiao Aigo(int **map, int *color) { + struct Zuobiao zuobiao; + zuobiao = action(map, *color); + map[zuobiao.row][zuobiao.col] = *color; + *color *= -1; + return zuobiao; +} +int main() { + Vector2 pos; + Vector2 pos2; + int color = black; + int map[15][15]; + int *p[15] = {map[0], map[1], map[2], map[3], map[4], map[5], map[6], map[7], + map[8], map[9], map[10], map[11], map[12], + map[13], map[14]}; + init(p, 15); + InitWindow(800, 800, ""); + SetTargetFPS(60); + struct Stack stack; + initStack(&stack); + drawChessboard(15, 50, p); + + while (!WindowShouldClose()) { + BeginDrawing(); + ClearBackground(BROWN); + if (IsMouseButtonPressed(MOUSE_BUTTON_MIDDLE)) { + struct Zuobiao zuobiao = Aigo(p, &color); + pos2.x = (zuobiao.row + 1) * 50; + pos2.y = (zuobiao.col + 1) * 50; + } + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { + int down = 0; + if (!gameOver(p, 15)) { + pos.x = GetMouseX(); + pos.y = GetMouseY(); + for (int i = 0; i < 15; i++) { + for (int j = 0; j < 15; j++) { + if (map[i][j] == 0 && pos.x > 25 + i * 50 && pos.x < 75 + i * 50 && pos.y > 25 + j * 50 && + pos.y < 75 + j * 50) { + map[i][j] = color; + down = 1;//假如确实下了子才变色 + } + } + } + if (down && !gameOver(p, 15)) { + color *= -1; + struct Zuobiao zuobiao = Aigo(p, &color); + pos2.x = (zuobiao.row + 1) * 50; + pos2.y = (zuobiao.col + 1) * 50; + } + } + if (down) { + pushStack(&stack, pos); + pushStack(&stack, pos2); + } + } + Regret2(p, 15, &stack); + Regret2(p, 15, &stack); + drawChessboard(15, 50, p); + if(gameOver(p,15)&&color==white){ + DrawText("Black wins",300,300,100,BLUE); + }if(gameOver(p,15)&&color==black){ + DrawText("White wins",300,300,100,RED); + } + EndDrawing(); + } + CloseWindow(); + return 0; +} diff --git a/aigobang2.exe b/aigobang2.exe new file mode 100644 index 0000000..4b639db Binary files /dev/null and b/aigobang2.exe differ diff --git a/level1/CMakeLists.txt b/level1/CMakeLists.txt index 7c004e8..58df5c9 100644 --- a/level1/CMakeLists.txt +++ b/level1/CMakeLists.txt @@ -1,21 +1,31 @@ project(level1) -add_executable(p01_running_letter p01_running_letter/main.c) -add_executable(p02_is_prime p02_is_prime/main.c) +add_executable(p01_running_letter p01_running_letter/main.c +) -add_executable(p03_all_primes p03_all_primes/main.c) +add_executable(p02_is_prime p02_is_prime/main.c -add_executable(p04_goldbach p04_goldbach/main.c) + p02_is_prime/isprime.c +) + +add_executable(p03_all_primes p03_all_primes/main.c + p03_all_primes/isprime2.c + p03_all_primes/isprime2.h) + +add_executable(p04_goldbach p04_goldbach/main.c + p04_goldbach/isprime3.c + p04_goldbach/isprime3.h) add_executable(p05_encrypt_decrypt p05_encrypt_decrypt/main.c) add_executable(p06_hanoi p06_hanoi/main.c) -add_executable(p07_maze p07_maze/main.c) +add_executable(p07_maze p07_maze/main.c ) add_executable(p08_push_boxes p08_push_boxes/main.c) add_executable(p09_linked_list p09_linked_list/main.c) -add_executable(p10_warehouse p10_warehouse/main.c) \ No newline at end of file +add_executable(p10_warehouse p10_warehouse/main.c) + diff --git a/level1/p01_running_letter/main.c b/level1/p01_running_letter/main.c index f84d224..73d2309 100644 --- a/level1/p01_running_letter/main.c +++ b/level1/p01_running_letter/main.c @@ -1,6 +1,33 @@ -#include - +#include +#include +#include +#include +#include +#define N 40 int main() { - printf("hello world!\n"); + int i,j,k; + char str[N]; + printf("璇疯緭鍏ヤ竴涓插瓧绗︿覆:"); + gets(str); + for(i=1;i<50;i++) + { + for(j=0;j1;i--) + { + for(k=0;k - -int main() { - printf("hello world!\n"); +#include +#include"isprime.h" +int isprime(int x); +int main(){ + int x; + scanf("%d",&x); + if (isprime(x)) { + printf("鏄礌鏁"); + }else{ + printf("涓嶆槸绱犳暟"); + } return 0; -} \ No newline at end of file +} diff --git a/level1/p03_all_primes/isprime2.c b/level1/p03_all_primes/isprime2.c new file mode 100644 index 0000000..596c910 --- /dev/null +++ b/level1/p03_all_primes/isprime2.c @@ -0,0 +1,20 @@ +// +// Created by 86182 on 2023/9/26. +// +// +// Created by 86182 on 2023/9/26. +// +#include +int isprime(int x) +{int ret=1; + int i; + for(i=3;i +#include +#include +#include"isprime2.h" +int main() +{ + double start,last; + start=clock(); + int first=3; + int end=1000; + int i,j; + printf("2\n"); + for(i=first;i +#include +#include"isprime3.h" +int main() +{int j; + int prime[1000]={2}; + int m=1; + for(j=3;j<1000;j+=2) + { + if(isprime(j)) + { + prime[m++]=j; + } + } + int x; + printf("请任意输入一个偶数:"); + scanf("%d",&x); + if(x>2&&x<=1000){ + if(x%2==0) + { + int i; + for(i=0;prime[i]!=0;i++) { + int k = x - prime[i]; + int l; + if (k <= prime[i]) { + for (l = 2; l < k; l++) { + + } + if (k == l) { + printf("%d=%d+%d\n", x, prime[i], k); + } + } + } + }else{ + printf("这不是一个偶数!"); + } + + + }else if(x>1000) + { + printf("你的数据太大了!"); + }else{ + printf("你的数据太小了"); + } -int main() { - printf("hello world!\n"); return 0; -} \ No newline at end of file +} diff --git a/level1/p05_encrypt_decrypt/main.c b/level1/p05_encrypt_decrypt/main.c index f84d224..9de622e 100644 --- a/level1/p05_encrypt_decrypt/main.c +++ b/level1/p05_encrypt_decrypt/main.c @@ -1,6 +1,37 @@ -#include - -int main() { - printf("hello world!\n"); - return 0; -} \ No newline at end of file +#include +#include +#define N 52 +void encode(char str[N],int n); +void decode(char str[N],int n); +int main() +{ +char str[N]; +int n; +printf("璇疯緭鍏ヤ竴涓瓧绗︿覆:"); +gets(str); +printf("璇疯緭鍏ヨ绉讳綅鐨勬暟瀛楀瘑閽:"); +scanf("%d",&n); +encode(str,n); + printf("鍔犲瘑鍚庣殑瀵嗘枃锛%s\n",str); +decode(str,n); +printf("瑙e瘑鍚庣殑鏄庢枃锛%s",str); + return 0; +} +void encode(char str[N],int n) +{int i; + for(i=0;i'z'||str[i]>"Z") + str[i]-=26; + } +} +void decode(char str[N],int n) +{int i; + for(i=0;i'z'||str[i]>"Z") + str[i]-=26; + } +} diff --git a/level1/p06_hanoi/main.c b/level1/p06_hanoi/main.c index f84d224..1e58bb7 100644 --- a/level1/p06_hanoi/main.c +++ b/level1/p06_hanoi/main.c @@ -1,6 +1,23 @@ -#include - -int main() { - printf("hello world!\n"); +#include +void hanoi(int n,char A,char B,char C); +int main() +{ + int n; + char A,B,C; + printf("请输入黄金圆盘的个数:"); + scanf("%d",&n); + hanoi( n, 'A', 'B', 'C'); return 0; +} +void hanoi(int n,char A,char B,char C) +{ + if(n==1) + { + printf("%c->%c\n",A,C); + + }else{ + hanoi(n-1,A,C,B); + printf("%c->%c\n",A,C); + hanoi(n-1,B,A, C); + } } \ No newline at end of file diff --git a/level1/p07_maze/main.c b/level1/p07_maze/main.c index f84d224..31f21cb 100644 --- a/level1/p07_maze/main.c +++ b/level1/p07_maze/main.c @@ -1,6 +1,116 @@ -#include - -int main() { - printf("hello world!\n"); +#include +#include +#define Row 10 +#define Col 10 +#include +#include +enum SpiriteType{ + Space,Wall,export,Human +}; +void draw(int **map,int m,int n){ + for(int i=0;i=0;i++){ + if(zuobiao.x=Row&&zuobiao.y==Col-1){ + printf("You win!"); + Sleep(750); + break; + } + draw(p,Row,Col); + zuobiao=Findperson(o,Row,Col,3); + run(q, Row, Col, zuobiao.x, zuobiao.y); + Sleep(50); + system("cls"); + } return 0; -} \ No newline at end of file +} diff --git a/level1/p08_push_boxes/main.c b/level1/p08_push_boxes/main.c index f84d224..f5b12a6 100644 --- a/level1/p08_push_boxes/main.c +++ b/level1/p08_push_boxes/main.c @@ -1,6 +1,217 @@ -#include - +#include +#include +#include +void draw(char **map, int m, int n){ + for(int i=0;i=0;i++){ + int conti=0; + for(int m=0;m<10;m++){ + for(int n=0;n<15;n++){ + if(arr[m][n]=='4') + conti=1; + } + } + draw(p,10,15); + zuobiao=Findperson(o,10,15,'2'); + run(q,10,15,zuobiao.x,zuobiao.y); + Sleep(50); + system("cls"); + if(conti==0) + break; + } + printf("You win!"); + } + else{ + printf("error!"); + } + Sleep(300); + fclose(file); + }else if(w=='2'){ + FILE *file = fopen("D:\\c2023-a\\level1\\p08_push_boxes\\map2.txt", "r"); + if(file!=NULL) { + char arr[8][21]; + char c; + for(int i=0;i<8;i++){ + for(int j=0;j<21;j++){ + c=getc(file); + + arr[i][j]=c; + } + } + char *p[21]={arr[0],arr[1],arr[2],arr[3],arr[4],arr[5],arr[6], + arr[7],arr[8],arr[9],arr[10],arr[11],arr[12],arr[13],arr[14], + arr[15],arr[16],arr[17],arr[18],arr[19],arr[20]}; + char *q[21]={arr[0],arr[1],arr[2],arr[3],arr[4],arr[5],arr[6], + arr[7],arr[8],arr[9],arr[10],arr[11],arr[12],arr[13],arr[14], + arr[15],arr[16],arr[17],arr[18],arr[19],arr[20]}; + char *o[21]={arr[0],arr[1],arr[2],arr[3],arr[4],arr[5],arr[6], + arr[7],arr[8],arr[9],arr[10],arr[11],arr[12],arr[13],arr[14], + arr[15],arr[16],arr[17],arr[18],arr[19],arr[20]}; + struct Zuobiao zuobiao; + for(int i=0;i>=0;i++){ + int conti=0; + for(int m=0;m<8;m++){ + for(int n=0;n<21;n++){ + if(arr[m][n]=='4') + conti=1; + } + } + draw(p,8,21); + zuobiao=Findperson(o,8,21,'2'); + run(q,8,21,zuobiao.x,zuobiao.y); + Sleep(50); + system("cls"); + if(conti==0) + break; + } + printf("You win!"); + } + else{ + printf("error!"); + } + Sleep(300); + fclose(file); + } +} diff --git a/level1/p08_push_boxes/map.txt b/level1/p08_push_boxes/map.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/level1/p08_push_boxes/map.txt @@ -0,0 +1 @@ + diff --git a/level1/p08_push_boxes/map1.txt b/level1/p08_push_boxes/map1.txt new file mode 100644 index 0000000..70fb09b --- /dev/null +++ b/level1/p08_push_boxes/map1.txt @@ -0,0 +1,10 @@ +11111111111111 +11110400111111 +11110300111111 +11000000000011 +11400020030411 +11003000000011 +11000003000011 +11111100001111 +11111104001111 +11111111111111 diff --git a/level1/p08_push_boxes/map2.txt b/level1/p08_push_boxes/map2.txt new file mode 100644 index 0000000..6fc9650 --- /dev/null +++ b/level1/p08_push_boxes/map2.txt @@ -0,0 +1,9 @@ +00001111000011110000 +00011000111100011000 +00110000000000001100 +00011000020000011000 +00001100300300110000 +00000110000001100000 +00000011044011000000 +00000001111110000000 + diff --git a/level1/p09_linked_list/main.c b/level1/p09_linked_list/main.c index f84d224..06af70c 100644 --- a/level1/p09_linked_list/main.c +++ b/level1/p09_linked_list/main.c @@ -1,6 +1,95 @@ -#include +#include +#include +struct ListNode{ + int element; + struct ListNode*next; +}; +typedef struct ListNode* Node; +void initList(Node node){ + node->next=NULL; +} +_Bool insertList(Node head,int element,int index){ + if(index<1) return 0; + while(--index){ + head=head->next; + if(head==NULL) return 0; + } + Node node = malloc(sizeof (struct ListNode)); + if(node==NULL) return 0; + node->element=element; + node->next=head->next; + head->next=node; + return 1; +} -int main() { - printf("hello world!\n"); +_Bool deleteList(Node head,int index){ + if(index<1) return 0; + while(--index){ + head=head->next; + if(head==NULL) return 0; + } + if(head->next==NULL) return 0; + Node tmp=head->next; + head->next=head->next->next; + free(tmp); + return 1; +} + void printList(Node head){ + while(head->next){ + head=head->next; + printf(" %d",head->element); + } + printf("\n"); +} +int findList(Node head,int element){ +head=head->next; +int i=1; +while(head){ + if(head->element==element) return i; + head=head->next; + i++; +} + return -1; +} +int findList2(Node head,int element){ + head=head->next; + int i=1; + int count=0; + while(head){ + if(head->element==element){ + if(count==1){ + return i; + }else count++; + } + head=head->next; + i++; + } + return -1; +} +struct ListNode exchangeList(Node head,int sizeList){ + struct ListNode head2; + initList(&head2); + for(int i= sizeList;i>0;i--){ + head=head->next; + insertList(&head2,head->element,1); + } + return head2; +} +int main(){ + struct ListNode head; + initList(&head); + for(int i=1;i<7;i++) { + insertList(&head, i, 1); + } + deleteList(&head,2); + printList(&head); + insertList(&head,5,1); + printList(&head); + printf("%d\n", findList(&head,5)); + printf("%d\n", findList2(&head,5)); + printList(&head); + struct ListNode head2=exchangeList(&head,6); + printList(&head2); + printf("%d\n", findList(&head2,5)); return 0; -} \ No newline at end of file +} diff --git a/level1/p10_warehouse/data.txt b/level1/p10_warehouse/data.txt new file mode 100644 index 0000000..b8a8590 --- /dev/null +++ b/level1/p10_warehouse/data.txt @@ -0,0 +1,7 @@ +99999 老板的金银财宝(无法打开) +55 huaweimate +3 huawei +3 苹果 +4 魅族 +5 htc +6 三星 diff --git a/level1/p10_warehouse/main.c b/level1/p10_warehouse/main.c index f84d224..d7d22f8 100644 --- a/level1/p10_warehouse/main.c +++ b/level1/p10_warehouse/main.c @@ -1,6 +1,138 @@ -#include +#include +#include +#include +#include +struct Box{ + int data; + char model[30]; +}; +struct NodeList{ + struct Box box; + struct NodeList *next; +}; +typedef struct NodeList* Node; +void initList(Node node){ + node->next=NULL; +} +_Bool insertList(Node head){ + printf("鍏ュ簱浣嶇疆锛"); + int index; + scanf("%d",&index); + if(index<1) return 0; + while(--index){ + head=head->next; + if(head==NULL) return 0; + } + Node node = malloc(sizeof (struct NodeList)); + if(node==NULL) return 0; + printf("鏁伴噺 鍨嬪彿锛歕n"); + scanf("%d %s",&node->box.data,node->box.model); + node->next=head->next; + head->next=node; + return 1; +} + +_Bool deleteList(Node head){ + int index; + printf("鍑哄簱浣嶇疆锛"); + scanf("%d",&index); + if(index<0) return 0; + while(--index){ + head=head->next; + if(head==NULL) return 0; + } + if(head==NULL) return 0; + Node tmp=head->next; + head->next=head->next->next; + free(tmp); + printf("鍑哄簱鎴愬姛\n"); + if(index<0) return 0; + return 1; +} +void printList(Node head){ + while(head){ + printf(" 鏁伴噺锛%d 鍨嬪彿锛%s\n",head->box.data,head->box.model); + head=head->next; + } +} +void warehouse(){ + for(int i=0;i<20;i++) + printf("*"); + printf("\n"); + printf("* 1搴撳瓨鍒楄〃 *"); + printf("\n"); + for(int i=0;i<20;i++) + printf("*"); + printf("\n"); + printf("* 2鍏ュ簱 *"); + printf("\n"); + for(int i=0;i<20;i++) + printf("*"); + printf("\n"); + printf("* 3鍑哄簱 *"); + printf("\n"); + for(int i=0;i<20;i++) + printf("*"); + printf("\n"); + printf("* 4閫鍑虹▼搴 *\n"); +} +void welcome(Node head){ + char c=getch(); + switch (c) + { + case'1': + printList(head);break; + case'2': + insertList(head);break; + case'3': + deleteList(head);break; + case'4': + Sleep(300); + printf("娆㈣繋鍐嶆浣跨敤锛"); + exit(0); + default: + printf("璇烽噸鏂拌緭鍏"); + break; + } +} +int main(){ + FILE *f=fopen("D:\\c2023-a\\level1\\p10_warehouse\\data.txt","r"); + if(f==NULL){ + printf("File not found!\n"); + return 0; + } + struct NodeList *head=NULL; + struct NodeList *tail=NULL; + while(!feof(f)){ + struct NodeList *node=(struct NodeList *)malloc(sizeof(struct NodeList)); + int s1=fscanf(f,"%d",&node->box.data); + int s2=fscanf(f,"%s",node->box.model); + if(s1!=1||s2!=1){ + break; + } + node->next=NULL; + if(head==NULL){ + head=node; + tail=node; + }else{ + tail->next=node; + tail=node; + } + } + fclose(f); + warehouse(); + while(1){ + printf("璇烽夋嫨浣犵殑鍔熻兘锛歕n"); + welcome(head); + f= fopen("D:\\c2023-a\\level1\\p10_warehouse\\data.txt","w"); + struct NodeList *p=head; + while(p!=NULL){ + fprintf(f,"%d %s\n",p->box.data,p->box.model); + p=p->next; + } + fclose(f); + } -int main() { - printf("hello world!\n"); return 0; -} \ No newline at end of file + +} diff --git a/raylib.dll b/raylib.dll new file mode 100644 index 0000000..8bd09d2 Binary files /dev/null and b/raylib.dll differ