From 8ab13a18f0afe4356562c96da3c567d8cceee9b7 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 28 Feb 2019 23:08:45 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=20=E5=AE=8C=E6=88=90=E4=BA=86running=20let?= =?UTF-8?q?ter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p01_runningLetter/main.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 level1/p01_runningLetter/main.c diff --git a/level1/p01_runningLetter/main.c b/level1/p01_runningLetter/main.c new file mode 100644 index 00000000..55aa6157 --- /dev/null +++ b/level1/p01_runningLetter/main.c @@ -0,0 +1,32 @@ +#include +#include +#define N 78 +unsigned int sleep(unsigned int seconds); +int main() +{ + int i,j; + while(1) + { + for(i=0;i0;i--) + { + for(j = 0;j <= i;j++) + { + printf(" "); + } + printf("s"); + Sleep(100); + system("cls"); + } + } + return 0; +} From f47846ca224cd8672c18f17e6b800d320626c8a3 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 9 Mar 2019 16:25:10 +0800 Subject: [PATCH 2/9] level1zuoye --- level1/p02_isPrime/sushu.c | 38 ++++++++++++++++++++++++ level1/p04_ narcissus/shuixian.c | 22 ++++++++++++++ level1/p05_allPrimes/allprimes.c | 29 ++++++++++++++++++ level1/p06_Goldbach/Goldbach.c | 33 ++++++++++++++++++++ level1/p07_encrypt_decrypt/jiamitijiao.c | 26 ++++++++++++++++ 5 files changed, 148 insertions(+) create mode 100644 level1/p02_isPrime/sushu.c create mode 100644 level1/p04_ narcissus/shuixian.c create mode 100644 level1/p05_allPrimes/allprimes.c create mode 100644 level1/p06_Goldbach/Goldbach.c create mode 100644 level1/p07_encrypt_decrypt/jiamitijiao.c diff --git a/level1/p02_isPrime/sushu.c b/level1/p02_isPrime/sushu.c new file mode 100644 index 00000000..3765635e --- /dev/null +++ b/level1/p02_isPrime/sushu.c @@ -0,0 +1,38 @@ +#include +int main() +{ + int num,i,count = 0; + printf("input a number:"); + scanf("%d",&num); + if(num <= 0) + { + printf("error!input again:");//重新输入一个正整数 + scanf("%d",&num); + } + else if(num == 1) + { + printf("N"); //1不是素数 + } + else if(num == 2) + { + printf("Y"); //2是素数 + } + else + { + for(i = 2;i < num;i++) + { + if(num%i == 0) + { + printf("N"); //不是素数 + break; + } + else + { + count++; + } + } + if(count == (num - 2)) + printf("Y"); //是素数 + } + return 0; +} diff --git a/level1/p04_ narcissus/shuixian.c b/level1/p04_ narcissus/shuixian.c new file mode 100644 index 00000000..5315f1f3 --- /dev/null +++ b/level1/p04_ narcissus/shuixian.c @@ -0,0 +1,22 @@ +#include +#include +#include +int main() +{ + int a,b,c,i,num; + + for(i=100;i<1000;i++) + { + num = i; + a=num%10; + num /= 10; + b=num%10; + num /= 10; + c = num; + if(i == (pow(a,3)+pow(b,3)+pow(c,3))) + { + printf("%d\n",i); + } + } + return 0; +} diff --git a/level1/p05_allPrimes/allprimes.c b/level1/p05_allPrimes/allprimes.c new file mode 100644 index 00000000..0f8c651e --- /dev/null +++ b/level1/p05_allPrimes/allprimes.c @@ -0,0 +1,29 @@ +#include +#include +#include +int main() +{ + clock_t start, finish; + double cost; + int i,j; + start=clock(); + printf("allPrimes:\n\n2 3 5 7 "); + for(i=5;i<1000;i += 2) + { + int count = 3; + for(j=3;j +int main() +{ + int num,i,j,a,count; + int primes[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; + for(num = 4;num < 100;num += 2) + { + for(i = 0;primes[i] < num;i++) + { + a = num - primes[i]; + count = 0; + for(j=0;j<25;j++) + { + if(a == primes[j]) + { + a = primes[j]; + break; + } + else + count++; + } + if(count<24) + { + printf("%-2d = %-2d + %d\n",num,a,primes[i]); + break; + } + } + } + printf("\nGoldbach's conjecture is right!\n"); + return 0; +} + + diff --git a/level1/p07_encrypt_decrypt/jiamitijiao.c b/level1/p07_encrypt_decrypt/jiamitijiao.c new file mode 100644 index 00000000..06226475 --- /dev/null +++ b/level1/p07_encrypt_decrypt/jiamitijiao.c @@ -0,0 +1,26 @@ +#include +#include +#include +#define N 5 //秘钥 +int main() +{ + char password[50]; + int i,count; + printf("请输入需要加密的密码:"); + gets(password); + count = strlen(password); + for(i = 0;i < count;i++) + { + password[i] = password[i] + i + N; + } + system("cls"); + printf("加密后的密码为:%s\n",password); + printf("按下任意键来解密\n"); + system("pause"); + for(i = 0;i < count;i++) + { + password[i] = password[i] - i - N; + } + printf("解密后密码是:%s",password); + return 0; +} From 4c96a1067d2a9a87fd3e740fb3996af9d23bb3a4 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 11 Mar 2019 22:22:14 +0800 Subject: [PATCH 3/9] new programmers --- level1/p03_Diophantus/diufantu.c | 14 ++++++++++++++ level1/p08_hanoi/hanoi.c | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 level1/p03_Diophantus/diufantu.c create mode 100644 level1/p08_hanoi/hanoi.c diff --git a/level1/p03_Diophantus/diufantu.c b/level1/p03_Diophantus/diufantu.c new file mode 100644 index 00000000..466c0ff6 --- /dev/null +++ b/level1/p03_Diophantus/diufantu.c @@ -0,0 +1,14 @@ +#include +//1/6x+1/12x+1/7x+5+1/2x+4=x +//转化为14x+7x+12x+5*84+42x+4*84=84x +int main() +{ + int i; + for(i = 0;i < 200;i++) //0-150每个年纪都试试!总活不过两百岁。 + { + if(14*i + 7*i + 12*i + 5*84 + 42*i + 4*84 == 84*i) + break; + } + printf("year = %d",i); + return 0; +} diff --git a/level1/p08_hanoi/hanoi.c b/level1/p08_hanoi/hanoi.c new file mode 100644 index 00000000..46f52aa0 --- /dev/null +++ b/level1/p08_hanoi/hanoi.c @@ -0,0 +1,24 @@ +#include +#include +void hanoi(int,char,char,char); +int main() +{ + int n; + printf("请输入圆盘个数:"); + scanf("%d",&n); + hanoi(n,'A','B','C'); + int count = pow(2,n) - 1; + printf("一共需要%d步。",count); + 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); + } +} From aef5fc9643302b1f46689f687afe19d920cb21dd Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 15 Mar 2019 21:26:50 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=93=A5=E5=BE=B7?= =?UTF-8?q?=E5=B7=B4=E8=B5=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p06_Goldbach/Goldbach.c | 33 ------------------------- level1/p06_Goldbach/newGoldbach.c | 40 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 33 deletions(-) delete mode 100644 level1/p06_Goldbach/Goldbach.c create mode 100644 level1/p06_Goldbach/newGoldbach.c diff --git a/level1/p06_Goldbach/Goldbach.c b/level1/p06_Goldbach/Goldbach.c deleted file mode 100644 index 4241da69..00000000 --- a/level1/p06_Goldbach/Goldbach.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -int main() -{ - int num,i,j,a,count; - int primes[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; - for(num = 4;num < 100;num += 2) - { - for(i = 0;primes[i] < num;i++) - { - a = num - primes[i]; - count = 0; - for(j=0;j<25;j++) - { - if(a == primes[j]) - { - a = primes[j]; - break; - } - else - count++; - } - if(count<24) - { - printf("%-2d = %-2d + %d\n",num,a,primes[i]); - break; - } - } - } - printf("\nGoldbach's conjecture is right!\n"); - return 0; -} - - diff --git a/level1/p06_Goldbach/newGoldbach.c b/level1/p06_Goldbach/newGoldbach.c new file mode 100644 index 00000000..ebe9beb9 --- /dev/null +++ b/level1/p06_Goldbach/newGoldbach.c @@ -0,0 +1,40 @@ +#include +//在100范围内验证哥德巴赫猜想的正确性 +//int isprime(int); +int main() +{ + int i,j,x,k; + int num ; + int primes[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; + for(i = 4;i < 100;i += 2) + { + + for(j = 0;j < 25;j++) + { + num = 0; + x = i - primes[j]; + for(k = 0;k<25;k++) + { + if(x==primes[k]) + num = 1; + } + //num = isprime(x); + if(!(x<2||num == 0||primes[j]>x)) + printf("%-3d= %-3d+ %-3d\n",i,primes[j],x); + } + } + return 0; +} +/*int isprime(int num) +{ + int i; + int primes[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; + for(i = 0;i< 25;i++) + { + if(num = primes[i]) + return 1; + } + return 0; + +} +*/ From 03ab6b5e5226410dc1ee0af40d765735d42cc696 Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 15 Mar 2019 21:30:38 +0800 Subject: [PATCH 5/9] =?UTF-8?q?new=20=E5=93=A5=E5=BE=B7=E5=B7=B4=E8=B5=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p06_Goldbach/newGoldbach.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/level1/p06_Goldbach/newGoldbach.c b/level1/p06_Goldbach/newGoldbach.c index ebe9beb9..d06ecb5f 100644 --- a/level1/p06_Goldbach/newGoldbach.c +++ b/level1/p06_Goldbach/newGoldbach.c @@ -1,6 +1,4 @@ #include -//在100范围内验证哥德巴赫猜想的正确性 -//int isprime(int); int main() { int i,j,x,k; @@ -18,23 +16,10 @@ int main() if(x==primes[k]) num = 1; } - //num = isprime(x); if(!(x<2||num == 0||primes[j]>x)) printf("%-3d= %-3d+ %-3d\n",i,primes[j],x); } } return 0; } -/*int isprime(int num) -{ - int i; - int primes[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; - for(i = 0;i< 25;i++) - { - if(num = primes[i]) - return 1; - } - return 0; -} -*/ From 4801a59026be4c43b1ab73095b374e60d57b6ec9 Mon Sep 17 00:00:00 2001 From: = <=> Date: Sun, 14 Apr 2019 21:56:11 +0800 Subject: [PATCH 6/9] maze --- level1/p09_maze/main.c | 170 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 level1/p09_maze/main.c diff --git a/level1/p09_maze/main.c b/level1/p09_maze/main.c new file mode 100644 index 00000000..56375462 --- /dev/null +++ b/level1/p09_maze/main.c @@ -0,0 +1,170 @@ +#include +#include +#include +#include +#define Height 25 //迷宫的高度,必须为奇数 +#define Width 25 //迷宫的宽度,必须为奇数 +#define Wall 1 +#define Road 0 +#define Start 2 +#define End 3 +#define Esc 5 +#define Up 1 +#define Down 2 +#define Left 3 +#define Right 4 +int map[Height+2][Width+2]; +void gotoxy(int x,int y) //移动坐标 +{ + COORD coord; + coord.X=x; + coord.Y=y; + SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord ); +} +void hidden()//隐藏光标 +{ + HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); + CONSOLE_CURSOR_INFO cci; + GetConsoleCursorInfo(hOut,&cci); + cci.bVisible=0;//赋1为显示,赋0为隐藏 + SetConsoleCursorInfo(hOut,&cci); +} +void create(int x,int y) //随机生成迷宫 +{ + int c[4][2]={0,1,1,0,0,-1,-1,0}; //四个方向 + int i,j,t; + //将方向打乱 + for(i=0;i<4;i++) + { + j=rand()%4; + t=c[i][0];c[i][0]=c[j][0];c[j][0]=t; + t=c[i][1];c[i][1]=c[j][1];c[j][1]=t; + } + map[x][y]=Road; + for(i=0;i<4;i++) + if(map[x+2*c[i][0]][y+2*c[i][1]]==Wall) + { + map[x+c[i][0]][y+c[i][1]]=Road; + create(x+2*c[i][0],y+2*c[i][1]); + } +} +int get_key() //接收按键 +{ + char c; + while(c=getch()) + { + if(c==27) return Esc; //Esc + if(c!=-32)continue; + c=getch(); + if(c==72) return Up; //上 + if(c==80) return Down; //下 + if(c==75) return Left; //左 + if(c==77) return Right; //右 + } + return 0; +} +void paint(int x,int y) //画迷宫 +{ + gotoxy(2*y-2,x-1); + switch(map[x][y]) + { + case Start: + printf("入");break; //画入口 + case End: + printf("出");break; //画出口 + case Wall: + printf("▇");break; //画墙 + case Road: + printf(" ");break; //画路 + } +} +void game() +{ + int x=2,y=1; //玩家当前位置,刚开始在入口处 + int c; //用来接收按键 + while(1) + { + gotoxy(2*y-2,x-1); + printf("●"); //画出玩家当前位置 + if(map[x][y]==End) //判断是否到达出口 + { + gotoxy(30,24); + printf("到达终点,按任意键结束"); + getch(); + break; + } + c=get_key(); + if(c==Esc) + { + gotoxy(0,24); + break; + } + switch(c) + { + case Up: //向上走 + if(map[x-1][y]!=Wall) + { + paint(x,y); + x--; + } + break; + case Down: //向下走 + if(map[x+1][y]!=Wall) + { + paint(x,y); + x++; + } + break; + case Left: //向左走 + if(map[x][y-1]!=Wall) + { + paint(x,y); + y--; + } + break; + case Right: //向右走 + if(map[x][y+1]!=Wall) + { + paint(x,y); + y++; + } + break; + } + } +} +int main() +{ + system("title yourname"); + int i,j; + srand((unsigned)time(NULL)); //初始化随即种子 + hidden(); //隐藏光标 + for(i=0;i<=Height+1;i++) + for(j=0;j<=Width+1;j++) + if(i==0||i==Height+1||j==0||j==Width+1) //初始化迷宫 + map[i][j]=Road; + else map[i][j]=Wall; + + create(2*(rand()%(Height/2)+1),2*(rand()%(Width/2)+1)); //从随机一个点开始生成迷宫,该点行列都为偶数 + for(i=0;i<=Height+1;i++) //边界处理 + { + map[i][0]=Wall; + map[i][Width+1]=Wall; + } + + for(j=0;j<=Width+1;j++) //边界处理 + { + map[0][j]=Wall; + map[Height+1][j]=Wall; + } + map[2][1]=Start; //给定入口 + map[Height-1][Width]=End; //给定出口 + for(i=1;i<=Height;i++) + { + for(j=1;j<=Width;j++) //画出迷宫 + paint(i,j); + } + game(); //开始游戏 + getch(); + return 0; +} + From 371c0af72518b30ac519307fa1678fd53f44daaa Mon Sep 17 00:00:00 2001 From: = <=> Date: Sat, 1 Jun 2019 21:59:53 +0800 Subject: [PATCH 7/9] +2 --- level1/p10_pushBoxes/README.md | 9 - level1/p10_pushBoxes/pushbox.c | 367 +++++++++++++++++++++++++++++++++ level1/p11_linkedList/main.c | 119 +++++++++++ 3 files changed, 486 insertions(+), 9 deletions(-) delete mode 100755 level1/p10_pushBoxes/README.md create mode 100644 level1/p10_pushBoxes/pushbox.c create mode 100644 level1/p11_linkedList/main.c diff --git a/level1/p10_pushBoxes/README.md b/level1/p10_pushBoxes/README.md deleted file mode 100755 index 5895c0d2..00000000 --- a/level1/p10_pushBoxes/README.md +++ /dev/null @@ -1,9 +0,0 @@ -### 棰樼洰锛氭帹绠卞瓙灏忔父鎴忥紙鍩轰簬console锛 - -### 鍔熻兘瑕佹眰锛 - -1. 灏唒09杩峰娓告垙鏀归犱负鈥滄帹绠卞瓙鈥濇父鎴忥紱 -1. 鍦ㄥ湴鍥句腑澧炲姞绠卞瓙銆佺瀛愮洰鏍囦綅缃瓑鍥惧舰锛 -1. 褰撶帺瀹跺皢鎵鏈夌瀛愬綊浣嶏紝鍒欐樉绀虹帺瀹惰耽寰椾簡娓告垙锛 -1. 鎸夌帺瀹惰蛋鍔ㄦ鏁拌鍒嗭紱 -1. 璁捐澶氫釜鍏冲崱锛屾瘡涓鍏崇殑鍦板浘浠庢枃浠朵腑璇诲彇锛岀帺瀹舵瘡鍏崇殑鍒嗘暟璁板綍鍒版枃浠朵腑锛 \ No newline at end of file diff --git a/level1/p10_pushBoxes/pushbox.c b/level1/p10_pushBoxes/pushbox.c new file mode 100644 index 00000000..f659d29c --- /dev/null +++ b/level1/p10_pushBoxes/pushbox.c @@ -0,0 +1,367 @@ +#include +#include +#include +int i,j; +void draw_map(int map[10][12]); +int main() +{ + char input; + int count=0; + int map[10][12] = { + {2,2,2,2,2,1,1,1,1,1,2,2}, + {1,1,1,1,2,1,0,0,0,1,1,2}, + {1,0,0,1,1,1,0,1,0,0,1,2}, + {1,0,4,3,3,3,3,3,1,0,1,1}, + {1,0,0,1,1,3,3,3,4,0,0,1}, + {1,0,0,0,0,4,1,1,4,1,0,1}, + {1,0,4,1,4,0,0,0,4,0,0,1}, + {1,1,0,6,0,1,1,1,4,1,0,1}, + {2,1,1,1,1,1,2,1,0,0,0,1}, + {2,2,2,2,2,2,2,1,1,1,1,1} + }; + while (1) + { + system("CLS"); + printf("\n"); + printf("\n"); + draw_map(map); + printf("当前得分:%d\n",count); + for (i=0;i<10;i++) + { + for (j=0;j<12;j++) + { + if (map[i][j]==6||map[i][j]==9) + break; + } + if (map[i][j]==6||map[i][j]==9) + break; + } + printf("您的当前坐标(%d,%d)",i,j); + input = getch(); + switch (input) + { + case 'w': + if(map[i-1][j]==0) + { + map[i-1][j]=6+0; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + else if((map[i-1][j]==3)||(map[i-1][j]==9)) + { + map[i-1][j]=6+3; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + else if(map[i-1][j]==4) + { + if (map[i-2][j]==0) + { + map[i-2][j]=4; + if(map[i-1][j]==7) + map[i-1][j]=9; + else + map[i-1][j]=6; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + else if (map[i-2][j]==3) + { + map[i-2][j]=7; + count++; + if(map[i-1][j]==7) + map[i-1][j]=9; + else + map[i-1][j]=6; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + } + else if(map[i-1][j]==7) + { + if(map[i-2][j]==0) + { + count--; + map[i-2][j]=4; + map[i-1][j]=9; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + if(map[i-2][j]==3) + { + map[i-2][j]=7; + map[i-1][j]=9; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + } + break; + case 's': + if(map[i+1][j]==0) + { + map[i+1][j]=6+0; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + else if(map[i+1][j]==3) + { + map[i+1][j]=6+3; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + else if(map[i+1][j]==4) + { + if (map[i+2][j]==0) + { + map[i+2][j]=4; + if(map[i+1][j]==7) + map[i+1][j]=9; + else + map[i+1][j]=6; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + else if (map[i+2][j]==3) + { + map[i-2][j]=7; + count++; + if(map[i+1][j]==7) + map[i+1][j]=9; + else + map[i+1][j]=6; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + } + else if(map[i+1][j]==7) + { + if(map[i+2][j]==0) + { + count--; + map[i+2][j]=4; + map[i+1][j]=9; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + if(map[i+2][j]==3) + { + map[i+2][j]=7; + map[i+1][j]=9; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + } + break; + case 'a': + if(map[i][j-1]==0) + { + map[i][j-1]=6+0; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + else if(map[i][j-1]==3) + { + map[i][j-1]=6+3; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + else if(map[i][j-1]==4) + { + if (map[i][j-2]==0) + { + map[i][j-2]=4; + + if(map[i][j-1]==7) + map[i][j-1]=9; + else + map[i][j-1]=6; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + else if (map[i][j-2]==3) + { + count++; + map[i][j-2]=7; + if(map[i][j-1]==7) + map[i][j-1]=9; + else + map[i][j-1]=6; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + } + else if(map[i][j-1]==7) + { + if(map[i][j-2]==0) + { + count--; + map[i][j-2]=4; + map[i][j-1]=9; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + if(map[i][j-2]==3) + { + map[i][j-2]=7; + map[i][j-1]=9; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + } + break; + case 'd': + if(map[i][j+1]==0) + { + map[i][j+1]=6+0; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + + else if(map[i][j+1]==3) + { + map[i][j+1]=6+3; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + else if(map[i][j+1]==4) + { + if (map[i][j+2]==0) + { + map[i][j+2]=4; + if(map[i][j+1]==7) + map[i][j+1]=9; + else + map[i][j+1]=6; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + else if (map[i][j+2]==3) + { + count++; + map[i][j+2]=7; + if(map[i][j+1]==7) + map[i][j+1]=9; + else + map[i][j+1]=6; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + } + else if(map[i][j+1]==7) + { + if(map[i][j+2]==0) + { + count--; + map[i][j+2]=4; + map[i][j+1]=9; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + if(map[i][j+2]==3) + { + map[i][j+2]=7; + map[i][j+1]=9; + if(map[i][j]==9) + map[i][j]=3; + else + map[i][j]=0; + } + } + break; + } + if(count==8) + { + system("CLS"); + draw_map(map); + break; + } + } + printf("\n恭喜你,过关了!!\n"); + return 0; +} +void draw_map(int map[10][12]) +{ + + for(i=0;i<10;i++) + { + for(j=0;j<12;j++) + { + switch(map[i][j]) + { + case 0: + printf(" "); + break; + case 1: + printf("#"); + break; + case 2: + printf(" "); + break; + case 3: + printf("!"); + break; + case 4: + printf("*"); + break; + case 7: + printf("$"); + break; + case 6: + printf("@"); + break; + case 9: + printf("@"); + break; + } + } + printf("\n"); + } +} + + diff --git a/level1/p11_linkedList/main.c b/level1/p11_linkedList/main.c new file mode 100644 index 00000000..8d967596 --- /dev/null +++ b/level1/p11_linkedList/main.c @@ -0,0 +1,119 @@ +#include +#include +struct Node +{ + int data; + struct Node * pNext; +}; +struct Node * CreateList(int len); +void TraverseList(struct Node * pHead); +void conTraverseList(struct Node * pHead,int len); +int find5(struct Node * pHead,int len); +int main(void) +{ + struct Node * pHead=NULL;//定义头指针,用来存放链表 + int len; + printf("请输入需要生成的链接节点的个数:len="); + scanf("%d",&len); + pHead=CreateList(len); + TraverseList(pHead); + printf("\n逆序后:\n"); + conTraverseList(pHead,len); + find5(pHead,len); + return 0; +} +struct Node * CreateList(int len) +{ + int i; + int val; + struct Node * pHead=(struct Node *)malloc(sizeof(struct Node)); + if(NULL==pHead) + { + printf("分配失败,程序终止!\n"); + exit(-1); + } + struct Node * pTail=pHead; + pTail->pNext=NULL; + + + for(i=0;idata=val; + pTail->pNext=pNew; + pNew->pNext=NULL; + pTail=pNew; + } + return pHead; +} + +void TraverseList(struct Node * pHead) +{ + struct Node * p=pHead->pNext; + if(pHead->pNext==NULL) + { + printf("链表为空!"); + } + else + { + while(p!=NULL) + { + printf("%d ",p->data); + p=p->pNext; + } + } +} +void conTraverseList(struct Node * pHead,int len) +{ + struct Node * p=pHead->pNext; + int j,i=0;; + if(pHead->pNext==NULL) + { + printf("链表为空!"); + } + else + { + for(i=0;ipNext; + if(j=len-i-1) + { + printf("%d ",p->data); + break; + } + + + } + } + } +} +int find5(struct Node * pHead,int len) +{ + int index=1; + struct Node * p=pHead->pNext; + for(int i=0;idata==5) + { + printf("值为5的节点序号是:%d ",index); + break; + } + index++; + } +} + + + + + From 49a7f15f15462ff9b20428569f715018a6993ee8 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 10 Jun 2019 19:09:34 +0800 Subject: [PATCH 8/9] 111 --- level1/p12_warehouse/amount.txt | 20 ++++ level1/p12_warehouse/goods.txt | 20 ++++ level1/p12_warehouse/main.c | 190 ++++++++++++++++++++++++++++++ level1/p12_warehouse/stockin.txt | 12 ++ level1/p12_warehouse/stockout.txt | 15 +++ 5 files changed, 257 insertions(+) create mode 100644 level1/p12_warehouse/amount.txt create mode 100644 level1/p12_warehouse/goods.txt create mode 100644 level1/p12_warehouse/main.c create mode 100644 level1/p12_warehouse/stockin.txt create mode 100644 level1/p12_warehouse/stockout.txt diff --git a/level1/p12_warehouse/amount.txt b/level1/p12_warehouse/amount.txt new file mode 100644 index 00000000..ab7dea26 --- /dev/null +++ b/level1/p12_warehouse/amount.txt @@ -0,0 +1,20 @@ +1 A1 456 0 0 456 400 +2 A2 23 0 0 23 100 +3 A3 67 0 0 67 100 +4 A4 104 0 0 104 100 +5 A5 78 0 0 78 100 +6 A6 630 0 0 630 500 +7 A7 92 0 0 92 100 +8 A8 162 0 0 162 100 +9 A9 401 0 0 401 200 +10 A10 276 0 0 276 200 +11 B1 400 0 0 400 400 +12 B2 989 0 0 989 400 +13 B3 194 0 0 194 100 +14 C1 495 0 0 495 200 +15 C2 287 0 0 287 200 +16 C3 88 0 0 88 100 +17 C4 933 0 0 933 500 +18 C5 56 0 0 56 100 +19 D1 786 0 0 786 600 +20 D2 237 0 0 237 100 diff --git a/level1/p12_warehouse/goods.txt b/level1/p12_warehouse/goods.txt new file mode 100644 index 00000000..b248b274 --- /dev/null +++ b/level1/p12_warehouse/goods.txt @@ -0,0 +1,20 @@ +1 A1 456 0 0 456 400 +2 A2 23 0 0 23 100 +3 A3 67 0 0 67 100 +4 A4 104 0 0 104 100 +5 A5 78 0 0 78 100 +6 A6 630 0 0 630 500 +7 A7 92 0 0 92 100 +8 A8 162 0 0 162 100 +9 A9 401 0 0 401 200 +10 A10 276 0 0 276 200 +11 B1 400 0 0 400 400 +12 B2 989 0 0 989 400 +13 B3 194 0 0 194 100 +14 C1 495 0 0 495 200 +15 C2 287 0 0 287 200 +16 C3 88 0 0 88 100 +17 C4 933 0 0 933 500 +18 C5 56 0 0 56 100 +19 D1 786 0 0 786 600 +20 D2 237 0 0 237 100 \ No newline at end of file diff --git a/level1/p12_warehouse/main.c b/level1/p12_warehouse/main.c new file mode 100644 index 00000000..e48c46ca --- /dev/null +++ b/level1/p12_warehouse/main.c @@ -0,0 +1,190 @@ +#include +#include +#include +#include +#define M 50 +/*实现如下的菜单(按数字选择菜单功能): +显示存货列表 +入库 +出库 +退出程序 +实现菜单对应功能(需记录货物的型号、数量等信息); +程序启动时从文件中读取当前库存数据,退出时保存库存数据; +*/ +typedef struct +{ + int num; //货品编号 + char name[20]; //货品名称 + int stock; //原始库存 + int in; //入库数目 + int out; //出库数目 + int amount; //最终库存 + int warning_value; + int state; //库存状态 +}goods; +goods s[M]; //用于存放货品信息 +goods r[M]; //用于存放入库货品信息 +goods t[M]; //用于存放出库货品信息 + +void Re_file(); +void Stock_in(); +void Stock_out(); +void Display(); +void Printf_back(); +void Modify(); +void Statistics(); +int Wr_file(); + +int N; +int P; + +int main() +{ + int sele; + Re_file(); //读取货品信息 + sele=1; + while(sele) + { + system("cls"); + printf("\n\n"); + printf("*********************************************\n"); + printf("* *\n"); + printf("* 1.入库 2.出库 *\n"); + printf("* *\n"); + printf("* *\n"); + printf("* 3.存货 4.退出 *\n"); + printf("* *\n"); + printf("*********************************************\n"); + printf("请选择功能序号:"); + scanf("%d",&sele); + switch(sele) + { + case 1:Stock_in();Display();break; + case 2:Stock_out();Display();break; + case 3:Statistics();break; + case 4:exit(0);sele=0;break; + } + printf("\n\n按任意键继续...\n"); + getch(); + } + Wr_file(); + return 0; +} + +void Re_file() //读入原始库存文件 +{ + FILE*fp; + N=0; + fp=fopen("goods.txt","r"); + while(fscanf(fp,"%d%s%d%d%d%d%d",&s[N].num,&s[N].name,&s[N].stock,&s[N].in,&s[N].out,&s[N].amount,&s[N].warning_value)!=EOF)N++; + fclose(fp); + P=N; +} + +void Stock_in() //读入入库文件 +{ + FILE*fp; + int i,j; + N=0; + fp=fopen("stockin.txt","r"); + while(fscanf(fp,"%d%d",&r[N].num,&r[N].in)!=EOF)N++; + fclose(fp); + for(i=0;i Date: Wed, 19 May 2021 14:29:55 +0800 Subject: [PATCH 9/9] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 34c10400..2938d987 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# c2019 +# 澶т竴c璇█浣滀笟 +#c2019 ## 鍩烘湰鎿嶄綔娴佺▼