diff --git a/level1/p01_runningLetter/level1_1.c b/level1/p01_runningLetter/level1_1.c new file mode 100644 index 00000000..613520af --- /dev/null +++ b/level1/p01_runningLetter/level1_1.c @@ -0,0 +1,32 @@ +#include +#include +#include +#define WIDTH 20 +int main() +{ + int x,y,z,s,w; + char a[WIDTH]; + for(x=1;x<=100;x++) + + { + if (x%2==1) + { + w=1; + } + else + { + w=-1; + } + {for(y=WIDTH*(1-w)/2;y!=WIDTH*(1+w)/2;y+=w) + {for(z=0;z +#include +int main() +{ + int x,y,z,w; + w=0; + printf("Plesse input a integer:\n"); + scanf("%d",&x); + y=sqrt(x); + for(z=2;z<=y;z++) + { + if((x/z*z)==x) + w=1; + } + + if(w!=0) + { + printf("%d is not prime\n",x); + } + else + { + printf("%d is prime\n",x); + } + return 0; +} diff --git a/level1/p03_Diophantus/level1_3.c b/level1/p03_Diophantus/level1_3.c new file mode 100644 index 00000000..42e85d6b --- /dev/null +++ b/level1/p03_Diophantus/level1_3.c @@ -0,0 +1,11 @@ +#include +int main() +{ + float x; + for(x=4;x<200;x++) + if(x/6+x/12+x/7+5+x/2+4==x) + { + printf("age=%.0f\n",x); + } + return 0; +} diff --git a/level1/p04_ narcissus/level1_4.c b/level1/p04_ narcissus/level1_4.c new file mode 100644 index 00000000..9008f47a --- /dev/null +++ b/level1/p04_ narcissus/level1_4.c @@ -0,0 +1,17 @@ +#include +int main() +{ + int x,a,b,c; + printf("Narcissistic numbes between 100~999 are as follows:"); + for(x=100;x<=999;x++) + { + a=x/100; + b=(x-a*100)/10; + c=x%10; + if(a*a*a+b*b*b+c*c*c==x) + { + printf(" %d",x); + } + } + return 0; +} diff --git a/level1/p05_allPrimes/main.c b/level1/p05_allPrimes/main.c new file mode 100644 index 00000000..13ee6ab5 --- /dev/null +++ b/level1/p05_allPrimes/main.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include"prime_under_1000.h" + +int main() +{ + int i,w;//i from 1 to 1000;w=return value + time_t begin,end; + + begin=clock(); + + printf("2");//other primes are all odd + for(i=3;i<=1000;i+=2) + { + if (prime(i)==0) + { + printf(",%d",i); + } + } + + end=clock(); + printf("\n\nTime used=%dms",end-begin); + return 0; +} diff --git a/level1/p05_allPrimes/prime_under_1000.h b/level1/p05_allPrimes/prime_under_1000.h new file mode 100644 index 00000000..0ff79d4d --- /dev/null +++ b/level1/p05_allPrimes/prime_under_1000.h @@ -0,0 +1,18 @@ +int prime(int x) +{ + int a[]={3,5,7,11,13,17,19,23,29,31,37};//sqrt(1000)<37 + int sqrt_x,i,w; + + sqrt_x=sqrt(x)+1; + w=0; + + for(i=0;a[i]<=sqrt_x;i++) + { + if(x%a[i]==0) + { + w=1; + break; + } + } + return w; +} diff --git a/level1/p06_Goldbach/Goldbach.h b/level1/p06_Goldbach/Goldbach.h new file mode 100644 index 00000000..4ff96146 --- /dev/null +++ b/level1/p06_Goldbach/Goldbach.h @@ -0,0 +1,24 @@ +int Goldbach(int x) +{ + int a[]={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}; + int i_1,i_2; + int w=0; + + for(i_1=0;i_1<=24;i_1++) + { + for(i_2=0;i_2<=24;i_2++) + { + if(x==a[i_1]+a[i_2]) + { + printf("%d=%d+%d\n",x,a[i_1],a[i_2]); + w++; + } + } + } + + if(w==0) + { + printf("Goldbach for %d is wrong!",x); + } +} + diff --git a/level1/p06_Goldbach/level1_6.dev b/level1/p06_Goldbach/level1_6.dev new file mode 100644 index 00000000..603cbd02 --- /dev/null +++ b/level1/p06_Goldbach/level1_6.dev @@ -0,0 +1,72 @@ +[Project] +FileName=level1_6.dev +Name=项目3 +Type=1 +Ver=2 +ObjFiles= +Includes= +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker= +IsCpp=1 +Icon= +ExeOutput= +ObjectOutput= +LogOutput= +LogOutputEnabled=0 +OverrideOutput=0 +OverrideOutputName= +HostApplication= +UseCustomMakefile=0 +CustomMakefile= +CommandLine= +Folders= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000000000000000 +UnitCount=2 + +[VersionInfo] +Major=1 +Minor=0 +Release=0 +Build=0 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 +SyncProduct=1 + +[Unit1] +FileName=main.c +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit2] +FileName=Goldbach.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/level1/p06_Goldbach/main.c b/level1/p06_Goldbach/main.c new file mode 100644 index 00000000..cac45abe --- /dev/null +++ b/level1/p06_Goldbach/main.c @@ -0,0 +1,14 @@ +#include +#include +#include"Goldbach.h" + +int main() +{ + int i; + for(i=4;i<=100;i+=2) + { + Goldbach(i); + printf("\n"); + } + return 0 ; +} diff --git a/level1/p07_encrypt_decrypt/Makefile.win b/level1/p07_encrypt_decrypt/Makefile.win new file mode 100644 index 00000000..cc6772de --- /dev/null +++ b/level1/p07_encrypt_decrypt/Makefile.win @@ -0,0 +1,28 @@ +# Project: decrypt +# Makefile created by Dev-C++ 5.11 + +CPP = g++.exe -D__DEBUG__ +CC = gcc.exe -D__DEBUG__ +WINDRES = windres.exe +OBJ = decrypt.o +LINKOBJ = decrypt.o +LIBS = -L"D:/Dev-Cpp/MinGW64/lib" -L"D:/Dev-Cpp/MinGW64/x86_64-w64-mingw32/lib" -static-libgcc -g3 +INCS = -I"D:/Dev-Cpp/MinGW64/include" -I"D:/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"D:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" +CXXINCS = -I"D:/Dev-Cpp/MinGW64/include" -I"D:/Dev-Cpp/MinGW64/x86_64-w64-mingw32/include" -I"D:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include" -I"D:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++" +BIN = decrypt.exe +CXXFLAGS = $(CXXINCS) -g3 +CFLAGS = $(INCS) -g3 +RM = rm.exe -f + +.PHONY: all all-before all-after clean clean-custom + +all: all-before $(BIN) all-after + +clean: clean-custom + ${RM} $(OBJ) $(BIN) + +$(BIN): $(OBJ) + $(CPP) $(LINKOBJ) -o $(BIN) $(LIBS) + +decrypt.o: decrypt.c + $(CPP) -c decrypt.c -o decrypt.o $(CXXFLAGS) diff --git a/level1/p07_encrypt_decrypt/decrypt.c b/level1/p07_encrypt_decrypt/decrypt.c new file mode 100644 index 00000000..d79a8f1d --- /dev/null +++ b/level1/p07_encrypt_decrypt/decrypt.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include"function_2.h" + +int main() +{ + char mingwen[200]={0},key[200]={0},miwen[200]={0}; + char ch; + int i; + + printf("Please input the key\n"); + input(key); + printf("Please input what you want to derypt:\n"); + input(miwen); + + decrypt(key,miwen,mingwen); + printf("mingwen:\n"); + output(mingwen); + + return 0; + + } diff --git a/level1/p07_encrypt_decrypt/decrypt.dev b/level1/p07_encrypt_decrypt/decrypt.dev new file mode 100644 index 00000000..05853b9a --- /dev/null +++ b/level1/p07_encrypt_decrypt/decrypt.dev @@ -0,0 +1,72 @@ +[Project] +FileName=decrypt.dev +Name=decrypt +Type=1 +Ver=2 +ObjFiles= +Includes= +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker= +IsCpp=1 +Icon= +ExeOutput= +ObjectOutput= +LogOutput= +LogOutputEnabled=0 +OverrideOutput=0 +OverrideOutputName= +HostApplication= +UseCustomMakefile=0 +CustomMakefile= +CommandLine= +Folders= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=1 +CompilerSettings=0000000000000000001000000 +UnitCount=2 + +[VersionInfo] +Major=1 +Minor=0 +Release=0 +Build=0 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 +SyncProduct=1 + +[Unit2] +FileName=function_2.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit1] +FileName=decrypt.c +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/level1/p07_encrypt_decrypt/decrypt.exe b/level1/p07_encrypt_decrypt/decrypt.exe new file mode 100644 index 00000000..f6eb2657 Binary files /dev/null and b/level1/p07_encrypt_decrypt/decrypt.exe differ diff --git a/level1/p07_encrypt_decrypt/decrypt.layout b/level1/p07_encrypt_decrypt/decrypt.layout new file mode 100644 index 00000000..fa56b4b8 --- /dev/null +++ b/level1/p07_encrypt_decrypt/decrypt.layout @@ -0,0 +1,13 @@ +[Editors] +Order=0,1 +Focused=1 +[Editor_0] +CursorCol=2 +CursorRow=16 +TopLine=1 +LeftChar=1 +[Editor_1] +CursorCol=40 +CursorRow=53 +TopLine=32 +LeftChar=1 diff --git a/level1/p07_encrypt_decrypt/decrypt.o b/level1/p07_encrypt_decrypt/decrypt.o new file mode 100644 index 00000000..2564aab1 Binary files /dev/null and b/level1/p07_encrypt_decrypt/decrypt.o differ diff --git a/level1/p07_encrypt_decrypt/encrypt.c b/level1/p07_encrypt_decrypt/encrypt.c new file mode 100644 index 00000000..c0bce64d --- /dev/null +++ b/level1/p07_encrypt_decrypt/encrypt.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include"function.h" + +int main() +{ + char mingwen[200]={0},key[200]={0},miwen[200]={0}; + char ch; + int i; + + printf("Please input the key:(purely use numbers)\n"); + input(key); + printf("Please input what you want to enrypt:\n"); + input(mingwen); + + encrypt(key,mingwen,miwen); + printf("miwen:\n"); + output(miwen); + + return 0; + + } diff --git a/level1/p07_encrypt_decrypt/encrypt.o b/level1/p07_encrypt_decrypt/encrypt.o new file mode 100644 index 00000000..9a4ee992 Binary files /dev/null and b/level1/p07_encrypt_decrypt/encrypt.o differ diff --git a/level1/p07_encrypt_decrypt/function.h b/level1/p07_encrypt_decrypt/function.h new file mode 100644 index 00000000..3715f5e1 --- /dev/null +++ b/level1/p07_encrypt_decrypt/function.h @@ -0,0 +1,59 @@ +int input(char a[]) +{ + int i; + char ch; + + i=0; + while((ch=getchar())!='\n') + { + a[i]=ch; + ++i; + } + + return 0; +} + +int output(char a[]) +{ + int i; + char ch; + + i=0; + while(a[i]!=0) + { + putchar(a[i]); + ++i; + } + + return 0; +} + +int encrypt(char key[],char mingwen[],char miwen[]) +{ + int length_key=strlen(key); + int length_mingwen=strlen(mingwen); + int i=0; + + for(;i + +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); + } +} + +int main() +{ + int n=4; + hanoi(n,'A','B','C'); + return 0; +} diff --git a/level1/p09_maze/level1_9.cpp b/level1/p09_maze/level1_9.cpp new file mode 100644 index 00000000..a93f80cd --- /dev/null +++ b/level1/p09_maze/level1_9.cpp @@ -0,0 +1,204 @@ +#include +#include +#include +#include +#include + +#define WIDTH 25 +#define LENGTH 25 + +#define start_point 'S' +#define end_point 'E' +#define wall 'O' +#define temp '*' +#define empty ' ' + +char maze[LENGTH][WIDTH]; +int temp_row,temp_line; + +void initialize(char(*maze_f)[WIDTH]) +{ + int i, j; + for (i = 0; i < LENGTH; i++) + { + for (j = 0; j < WIDTH; j++) + { + maze_f[i][j] = wall; + } + } + maze_f[1][0] = start_point; + temp_row=1; + temp_line=1; + maze_f[temp_row][temp_line] = empty; + + maze_f[LENGTH - 2][WIDTH - 1] = end_point;//出口坐标 +} + +void print_maze(char(*maze_f)[WIDTH]) +{ + printf("*shows where you are,and you should move to the point 'E'\n"); + int i, j; + for (i = 0; i<=WIDTH + 1; i++) + { + putchar('_'); + } + putchar('\n'); + for (i = 0; i < LENGTH; i++) + { + putchar('|'); + for (j = 0; j < WIDTH; j++) + { + putchar(maze[i][j]); + } + putchar('|'); + putchar('\n'); + } + for (i = 0; i <= WIDTH + 1; i++) + { + putchar('-'); + } + + return; +} + +void create(char(*maze)[WIDTH]) +//先生成通路,后面随机生成空格干扰 +{ + int direction; + int i,j,n; + //if(maze[LENGTH-2][WIDTH-2]!=empty) + { + direction=rand()%4; + switch(direction) + { + case 0://UP + if(maze[temp_row-1][temp_line]!=empty&&temp_row>1) + { + temp_row--; + maze[temp_row][temp_line]=empty; + } + break; + case 1://DOWN + if(maze[temp_row+1][temp_line]!=empty&&temp_row1) + { + temp_line--; + maze[temp_row][temp_line]=empty; + } + break; + case 3://RIGHT + if(maze[temp_row][temp_line+1]!=empty&&temp_line F:\coding\c2019\level1\p10_pushBoxes\push_box\Debug\push_box.exe diff --git a/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/CL.command.1.tlog b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/CL.command.1.tlog new file mode 100644 index 00000000..01f08455 Binary files /dev/null and b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/CL.command.1.tlog differ diff --git a/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/CL.read.1.tlog b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/CL.read.1.tlog new file mode 100644 index 00000000..b1e5fe1a Binary files /dev/null and b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/CL.read.1.tlog differ diff --git a/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/CL.write.1.tlog b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/CL.write.1.tlog new file mode 100644 index 00000000..4633c400 Binary files /dev/null and b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/CL.write.1.tlog differ diff --git a/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/link.command.1.tlog b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/link.command.1.tlog new file mode 100644 index 00000000..1fb93207 Binary files /dev/null and b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/link.command.1.tlog differ diff --git a/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/link.read.1.tlog b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/link.read.1.tlog new file mode 100644 index 00000000..d5936a82 Binary files /dev/null and b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/link.read.1.tlog differ diff --git a/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/link.write.1.tlog b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/link.write.1.tlog new file mode 100644 index 00000000..3f94a8c5 Binary files /dev/null and b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/link.write.1.tlog differ diff --git a/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/push_box.lastbuildstate b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/push_box.lastbuildstate new file mode 100644 index 00000000..380a6395 --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/Debug/push_box.tlog/push_box.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.17763.0 +Debug|Win32|F:\coding\c2019\level1\p10_pushBoxes\push_box\| diff --git a/level1/p10_pushBoxes/push_box/push_box/Debug/vc141.idb b/level1/p10_pushBoxes/push_box/push_box/Debug/vc141.idb new file mode 100644 index 00000000..9cf7cbea Binary files /dev/null and b/level1/p10_pushBoxes/push_box/push_box/Debug/vc141.idb differ diff --git a/level1/p10_pushBoxes/push_box/push_box/Debug/vc141.pdb b/level1/p10_pushBoxes/push_box/push_box/Debug/vc141.pdb new file mode 100644 index 00000000..eefb198c Binary files /dev/null and b/level1/p10_pushBoxes/push_box/push_box/Debug/vc141.pdb differ diff --git a/level1/p10_pushBoxes/push_box/push_box/Release/push_box.log b/level1/p10_pushBoxes/push_box/push_box/Release/push_box.log new file mode 100644 index 00000000..e08f848b --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/Release/push_box.log @@ -0,0 +1,17 @@ +锘 game.cpp +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\game.h(4): error C2018: 鏈煡瀛楃鈥0x7f鈥 +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\game.h(6): error C2018: 鏈煡瀛楃鈥0x7f鈥 +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\game.cpp(3): error C2018: 鏈煡瀛楃鈥0x7f鈥 +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\game.cpp(6): error C2018: 鏈煡瀛楃鈥0x7f鈥 +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\game.cpp(8): error C2018: 鏈煡瀛楃鈥0x7f鈥 +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\game.cpp(27): warning C4553: 鈥==鈥: 鏈娇鐢ㄨ〃杈惧紡缁撴灉锛涙槸鍚︽墦绠椾娇鐢ㄢ=鈥? +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\game.cpp(77): warning C4553: 鈥==鈥: 鏈娇鐢ㄨ〃杈惧紡缁撴灉锛涙槸鍚︽墦绠椾娇鐢ㄢ=鈥? + main.cpp +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\game.h(4): error C2018: 鏈煡瀛楃鈥0x7f鈥 +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\game.h(6): error C2018: 鏈煡瀛楃鈥0x7f鈥 +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\map.h(5): error C2018: 鏈煡瀛楃鈥0x7f鈥 + map.cpp +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\map.h(5): error C2018: 鏈煡瀛楃鈥0x7f鈥 +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\map.cpp(3): error C2018: 鏈煡瀛楃鈥0x7f鈥 +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\map.cpp(6): error C2018: 鏈煡瀛楃鈥0x7f鈥 +f:\coding\c2019\level1\p10_pushboxes\push_box\push_box\map.cpp(9): error C2018: 鏈煡瀛楃鈥0x7f鈥 diff --git a/level1/p10_pushBoxes/push_box/push_box/Release/push_box.tlog/CL.command.1.tlog b/level1/p10_pushBoxes/push_box/push_box/Release/push_box.tlog/CL.command.1.tlog new file mode 100644 index 00000000..46b134b1 --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/Release/push_box.tlog/CL.command.1.tlog @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/level1/p10_pushBoxes/push_box/push_box/Release/push_box.tlog/push_box.lastbuildstate b/level1/p10_pushBoxes/push_box/push_box/Release/push_box.tlog/push_box.lastbuildstate new file mode 100644 index 00000000..ceb35554 --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/Release/push_box.tlog/push_box.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.17763.0 +Release|Win32|F:\coding\c2019\level1\p10_pushBoxes\push_box\| diff --git a/level1/p10_pushBoxes/push_box/push_box/Release/push_box.tlog/unsuccessfulbuild b/level1/p10_pushBoxes/push_box/push_box/Release/push_box.tlog/unsuccessfulbuild new file mode 100644 index 00000000..e69de29b diff --git a/level1/p10_pushBoxes/push_box/push_box/Release/vc141.pdb b/level1/p10_pushBoxes/push_box/push_box/Release/vc141.pdb new file mode 100644 index 00000000..764dd1dc Binary files /dev/null and b/level1/p10_pushBoxes/push_box/push_box/Release/vc141.pdb differ diff --git a/level1/p10_pushBoxes/push_box/push_box/basic.h b/level1/p10_pushBoxes/push_box/push_box/basic.h new file mode 100644 index 00000000..8d60208e --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/basic.h @@ -0,0 +1,7 @@ +#define player 'H' +#define box 'O' +#define target 'T' +#define wall '*' +#define empty ' ' +#define bt 'C'//已经推到目标上的箱子 +#define pt 'h'//玩家站在目标上 diff --git a/level1/p10_pushBoxes/push_box/push_box/game.cpp b/level1/p10_pushBoxes/push_box/push_box/game.cpp new file mode 100644 index 00000000..2266023b --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/game.cpp @@ -0,0 +1,241 @@ +#include "game.h" + +int win(char(*map)[15])//已经完成则返回1,没有则返回0 +{ + int i, j; + for (i = 0; i<15; i++) + { + for (j = 0;j<15; j++) + { + if (map[i][j] == target||map[i][j]==pt) + { + return 0; + } + } + } + return 1; +} + +int move(char(*map)[15]) +{ + game_menu(); + print(map); + int score = 1000; + while (!win(map)) + { + int i, j; + int row, line; + for (i = 0; i < 15; i++) + { + for (j = 0; j < 15; j++) + { + if (map[i][j] == player || map[i][j] == pt) + { + row = i; + line = j; + break; + } + } + } + + char ch = _getch(); + switch (ch) + { + case 72: + move_onstep(&map[row][line], &map[row - 1][line], &map[row - 2][line], &score); + game_menu(); + print(map); + score--; + break; + case 80: + move_onstep(&map[row][line], &map[row + 1][line], &map[row + 2][line], &score); + game_menu(); + print(map); + score--; + break; + case 75: + move_onstep(&map[row][line], &map[row][line - 1], &map[row][line - 2], &score); + game_menu(); + print(map); + score--; + break; + case 77: + move_onstep(&map[row][line], &map[row][line + 1], &map[row][line + 2], &score); + game_menu(); + print(map); + score--; + break; + case'r':return 0; + case'R':return 0; + } + + } + if (win(map) == 1) + { + printf("Completed!"); + system("pause"); + return score; + } +} + +void move_onstep(char * play, char * forward1, char * forward2,int *score) +{ + //玩家当前的位置为H + if (*play == player) + { + if (*forward1 == empty) + { + + *play = empty; + *forward1 = player; + + return; + } + if (*forward1 == target) + { + *play = empty; + *forward1 = pt; + + return; + } + if (*forward1 == box) + { + if (*forward2 == empty) + { + *forward2 = box; + *forward1 = player; + *play = empty; + + return; + } + if (*forward2 == target) + { + *forward2 = bt; + *forward1 = player; + *play = empty; + + return; + } + } + if (*forward1 == bt) + { + if (*forward2 == empty) + { + *forward2 = box; + *forward1 = pt; + *play = empty; + + return; + } + if (*forward2 == target) + { + *forward2 = bt; + *forward1 = pt; + *play = empty; + + return; + } + } + } + //玩家当前的位置为h + if (*play == pt) + { + if (*forward1 == empty) + { + *play = target; + *forward1 = player; + + return; + } + if (*forward1 == target) + { + *play = target; + *forward1 = pt; + + return; + } + if (*forward1 == box) + { + if (*forward2 == empty) + { + *forward2 = box; + *forward1 = player; + *play = target; + + return; + } + if (*forward2 == target) + { + *forward2 = bt; + *forward1 = player; + *play = target; + + return; + } + } + if (*forward1 == bt) + { + if (*forward2 == empty) + { + *forward2 = box; + *forward1 = pt; + *play = target; + + return; + } + if (*forward2 == target) + { + *forward2 = bt; + *forward1 = pt; + *play = target; + + return; + } + } + } +} + +void main_menu(void) +{ + system("cls"); + printf("\tInput a number to start\n"); + printf("\t1:Easy game.\n"); + printf("\t2:Hard game.\n"); + printf("\tQ:Exit."); + + return; +} + +void game_menu(void) +{ + system("cls"); + printf("\tUse direction keys to move.\n"); + printf("\tSymbols meaning:\n"); + printf("\tH:Player\n"); + printf("\tO:Boxes\n"); + printf("\t*:Walls\n"); + printf("\tT:Target\n"); + printf("\tC:Boxes on the target\n"); + printf("\th:Player on the target\n"); + printf("\n\tPress R to return to the main menu.\n\n"); + return; +} + +void record(int number, int score) +{ + const char ch= '\n'; + if (number == 1) + { + FILE *fp = fopen("score1.txt", "a+"); + fwrite(&score, sizeof(int), 1, fp); + fwrite(&ch, sizeof('\n'), 1, fp); + fclose(fp); + } + if (number == 2) + { + FILE *fp = fopen("score2.txt", "a+"); + fwrite(&score, sizeof(int), 1, fp); + fwrite(&ch, sizeof('\n'), 1, fp); + fclose(fp); + } +} diff --git a/level1/p10_pushBoxes/push_box/push_box/game.h b/level1/p10_pushBoxes/push_box/push_box/game.h new file mode 100644 index 00000000..e9500273 --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/game.h @@ -0,0 +1,16 @@ +#include"basic.h" +#include"map.h" +#include +#include +#include +int win(char(*map)[15]);//已经完成则返回1,没有则返回0 + +int move(char(*map)[15]); + +void move_onstep(char *play, char *forward1, char *forward2,int * score);//play是玩家当前所在的格子,forward1是前进方向的第一格,forward2是第二格,根据不同情况决定移动后的操作 + +void main_menu(void); + +void game_menu(void); + +void record(int number, int score);//记录分数 \ No newline at end of file diff --git a/level1/p10_pushBoxes/push_box/push_box/main.cpp b/level1/p10_pushBoxes/push_box/push_box/main.cpp new file mode 100644 index 00000000..1f8f710b --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/main.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include"basic.h" +#include"game.h" +#include"map.h" +#pragma warning(disable : 4996)//在VS里fopen没法直接使用,必须关掉警告 + +int main() +{ + char map[15][15]; + + char order[100] = { 0 }; + while (1) + { + int score; + main_menu(); + putchar('\n'); + gets_s(order); + switch (order[0]) + { + case '1':loadmap(1, map); score = move(map); record(1, score); break; + case '2':loadmap(2, map); score = move(map); record(2, score); break; + case'q':exit(1); + case'Q':exit(1); + default:printf("Reinput your order!"); system("pause"); + } + } + +} \ No newline at end of file diff --git a/level1/p10_pushBoxes/push_box/push_box/map.cpp b/level1/p10_pushBoxes/push_box/push_box/map.cpp new file mode 100644 index 00000000..5f84a20b --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/map.cpp @@ -0,0 +1,46 @@ +#include"map.h" +void print(char(*map)[15]) +{ + int i, j; + for (i = 0;i<15; i++) + { + putchar('\t'); + for (j = 0;j<15; j++) + { + putchar(map[i][j]); + } + putchar('\n'); + } + return; +} + +void loadmap(int number, char(*map)[15]) +{ + if (number == 1) + { + FILE*fp = fopen("map1.txt", "r"); + int i, j; + for (i = 0; i < 15; i++) + { + for (j = 0; j < 15; j++) + { + fread(&map[i][j], sizeof(map[0][0]), 1, fp); + } + } + fclose(fp); + } + if (number == 2) + { + FILE*fp = fopen("map2.txt", "r"); + int i, j; + for (i = 0; i < 15; i++) + { + for (j = 0; j < 15; j++) + { + fread(&map[i][j], sizeof(map[0][0]), 1, fp); + } + } + fclose(fp); + } + +} \ No newline at end of file diff --git a/level1/p10_pushBoxes/push_box/push_box/map.h b/level1/p10_pushBoxes/push_box/push_box/map.h new file mode 100644 index 00000000..83219aa2 --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/map.h @@ -0,0 +1,7 @@ +#include"basic.h" +#include +#pragma warning(disable : 4996)//在VS里fopen没法直接使用,必须关掉警告 + +void print(char(*map)[15]); + +void loadmap(int number, char(*map)[15]); \ No newline at end of file diff --git a/level1/p10_pushBoxes/push_box/push_box/map1.txt b/level1/p10_pushBoxes/push_box/push_box/map1.txt new file mode 100644 index 00000000..9fa3cbb1 --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/map1.txt @@ -0,0 +1 @@ +********************************H O T********* ********* ********* O *********O *********T T**************************************************************************************************************** \ No newline at end of file diff --git a/level1/p10_pushBoxes/push_box/push_box/map2.txt b/level1/p10_pushBoxes/push_box/push_box/map2.txt new file mode 100644 index 00000000..8376cead --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/map2.txt @@ -0,0 +1 @@ +******************************************************************* *********T O** ********TTO O H*******TT O O ************* ********************************************************************************************** \ No newline at end of file diff --git a/level1/p10_pushBoxes/push_box/push_box/push_box.vcxproj b/level1/p10_pushBoxes/push_box/push_box/push_box.vcxproj new file mode 100644 index 00000000..a779356a --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/push_box.vcxproj @@ -0,0 +1,130 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {6ADECCAD-ABFA-4C8B-BE62-F5FFBD510A66} + pushbox + 10.0.17763.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/level1/p10_pushBoxes/push_box/push_box/push_box.vcxproj.filters b/level1/p10_pushBoxes/push_box/push_box/push_box.vcxproj.filters new file mode 100644 index 00000000..9d9a5d8d --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/push_box.vcxproj.filters @@ -0,0 +1,39 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + \ No newline at end of file diff --git a/level1/p10_pushBoxes/push_box/push_box/push_box.vcxproj.user b/level1/p10_pushBoxes/push_box/push_box/push_box.vcxproj.user new file mode 100644 index 00000000..be250787 --- /dev/null +++ b/level1/p10_pushBoxes/push_box/push_box/push_box.vcxproj.user @@ -0,0 +1,4 @@ +锘 + + + \ No newline at end of file diff --git a/level1/p10_pushBoxes/push_box/push_box/score1.txt b/level1/p10_pushBoxes/push_box/push_box/score1.txt new file mode 100644 index 00000000..cbbe329e Binary files /dev/null and b/level1/p10_pushBoxes/push_box/push_box/score1.txt differ diff --git a/level1/p10_pushBoxes/push_box/push_box/score2.txt b/level1/p10_pushBoxes/push_box/push_box/score2.txt new file mode 100644 index 00000000..617c54f6 Binary files /dev/null and b/level1/p10_pushBoxes/push_box/push_box/score2.txt differ diff --git a/level1/p11_linkedList/function.h b/level1/p11_linkedList/function.h new file mode 100644 index 00000000..30810ea5 --- /dev/null +++ b/level1/p11_linkedList/function.h @@ -0,0 +1,137 @@ +typedef struct List +{ + int value;//数据域 + struct List * pNext;//指针域,因为要指向下一个结点,所以这个pNext指针必须是 List * 类型的 +}NODE,* PNODE; + +PNODE create(void) +{ + PNODE pHead = (PNODE)malloc(sizeof(NODE));//先给首结点分配空间,不存放有效数据 + + + int i,len,val;//len:需要创建的链表有效结点数,val:临时存放用户输入的当前结点的值 + PNODE pTail = pHead;//pTail的功能见后面 + pHead->pNext=NULL; + pTail->pNext = NULL; + + if (pHead == NULL)//分配失败 + { + printf("Failed to allocate,program stop soon!"); + exit(-1); + } + + + printf("input how many values:\n"); + scanf("%d", &len);//获取需要创建的链表有效结点数(因为头结点一般不认为是有效结点) + if(len>=0) + { + for (i = 0; i < len; i++) + { + printf("Input NO.%d value:",i + 1);//数据结构一般符合人类习惯,不用像数组一样下标-1 + scanf("%d", &val);//还没有分配空间给当前数据,暂时存放于val中 + + PNODE pNew= (PNODE)malloc(sizeof(NODE));//给这个数据分配空间,用pNew表示这个新空间的地址 + if (pNew== NULL)//分配失败 + { + printf("Failed to allocate,program stop soon!"); + exit(-1); + } + pNew->value = val;//将val的值存入链表中 + pTail->pNext = pNew;//错误的写法:pHead->pNext = pNew;导致所有结点都挂在pHead! + //将新创建的结点挂到原链表的最后一个结点的后面,假设有一个指针pTail时刻指向尾结点,那么只需pTail->pNext=pNew即可 + pNew->pNext = NULL;//此时新结点是最后一个结点,指向NULL + pTail = pNew;//再次将pTail移动到指向最后一个结点 + } + } + else + { + printf("Error!"); + } + + return pHead;//返回值为首结点的地址,这样就便于对链表进行操作 +} + +void print_all(PNODE pHead)//遍历链表并输出 +{ + PNODE p=pHead->pNext;//将p指向头结点 + + while(p!=NULL)//没有指向最后一个结点/链表中只有头结点 + { + printf("%d ",p->value); + p=p->pNext;//移位 + } + printf("\n");//结束后换行 + + return; +} + +void find_value(PNODE pHead,int val,int num) +{ + PNODE p=pHead; + int i,n=0;//i:结点序号;n:已找到的val的个数 + while(p->pNext!=NULL&&npNext; + i++; + if(p->value==val) + { + n++; + } + if(n==num) + { + printf("%d",i); + return; + } + } + if(p->pNext==NULL) + { + printf("-1"); + return; + } +} + +int find_value_of_node(PNODE pHead,int n) +{ + int i; + PNODE p=pHead->pNext; + for(i=1;i<=n;i++) + { + p=p->pNext; + } + + return(p->value); +} + +void change_value_of_node(PNODE pHead,int n,int val) +{ + int i; + PNODE p=pHead->pNext; + for(i=1;i<=n;i++) + { + p=p->pNext; + } + p-> value=val; +} + +void reverse(PNODE pHead) +{ + int n,i,t; + PNODE p=pHead; + while(p->pNext!=NULL) + { + p=p->pNext; + i++; + }//统计链表总的结点数 + n=i; + for(i=1;i<=n/2;i++) + { + t=find_value_of_node(pHead,i);//找到第i个结点的数据,暂存t + change_value_of_node(pHead,i,find_value_of_node(pHead,n-i));//把第i个结点中的数改为第n-i个中的 + change_value_of_node(pHead,n-i,t);//把第n-i个结点中的改为t + } + return; +} + + + + diff --git a/level1/p11_linkedList/function.h.gch b/level1/p11_linkedList/function.h.gch new file mode 100644 index 00000000..f84c6278 Binary files /dev/null and b/level1/p11_linkedList/function.h.gch differ diff --git a/level1/p11_linkedList/main.cpp b/level1/p11_linkedList/main.cpp new file mode 100644 index 00000000..18feb230 --- /dev/null +++ b/level1/p11_linkedList/main.cpp @@ -0,0 +1,28 @@ +#include +#include +#include"function.h" + + + + +int main() +{ + PNODE pHead = NULL;//等价于struct List *pHead=NULL + pHead = create();//函数——创建链表,其中返回值为首结点的地址,这样就便于对链表进行操作 + + printf("该链表中的数据依次是:\n"); + print_all(pHead);// + + printf("第一个5的结点位置:\n"); + find_value(pHead,5,1); + printf("\n第二次出现5的结点位置是:\n"); + find_value(pHead,5,2); + + printf("\n反序结果为:\n"); + reverse(pHead); + print_all(pHead); + + return 0; +} + + diff --git a/level1/p11_linkedList/main.exe b/level1/p11_linkedList/main.exe new file mode 100644 index 00000000..8d1d4551 Binary files /dev/null and b/level1/p11_linkedList/main.exe differ diff --git a/level1/p11_linkedList/main.o b/level1/p11_linkedList/main.o new file mode 100644 index 00000000..41875b54 Binary files /dev/null and b/level1/p11_linkedList/main.o differ diff --git a/level1/p12_warehouse/README.md b/level1/p12_warehouse/README.md deleted file mode 100755 index cd146f6a..00000000 --- a/level1/p12_warehouse/README.md +++ /dev/null @@ -1,11 +0,0 @@ -### 棰樼洰锛氱畝鍗曡繘閿瀛 - -### 鍔熻兘瑕佹眰锛 - -1. 瀹炵幇濡備笅鐨勮彍鍗曪紙鎸夋暟瀛楅夋嫨鑿滃崟鍔熻兘锛夛細 - - 鏄剧ず瀛樿揣鍒楄〃 - - 鍏ュ簱 - - 鍑哄簱 - - 閫鍑虹▼搴 -1. 瀹炵幇鑿滃崟瀵瑰簲鍔熻兘锛堥渶璁板綍璐х墿鐨勫瀷鍙枫佹暟閲忕瓑淇℃伅锛夛紱 -1. 绋嬪簭鍚姩鏃朵粠鏂囦欢涓鍙栧綋鍓嶅簱瀛樻暟鎹紝閫鍑烘椂淇濆瓨搴撳瓨鏁版嵁锛 \ No newline at end of file diff --git a/level1/p12_warehouse/warehouse/.vs/warehouse/v15/.suo b/level1/p12_warehouse/warehouse/.vs/warehouse/v15/.suo new file mode 100644 index 00000000..05e3f43b Binary files /dev/null and b/level1/p12_warehouse/warehouse/.vs/warehouse/v15/.suo differ diff --git a/level1/p12_warehouse/warehouse/.vs/warehouse/v15/Browse.VC.db b/level1/p12_warehouse/warehouse/.vs/warehouse/v15/Browse.VC.db new file mode 100644 index 00000000..347974b7 Binary files /dev/null and b/level1/p12_warehouse/warehouse/.vs/warehouse/v15/Browse.VC.db differ diff --git a/level1/p12_warehouse/warehouse/.vs/warehouse/v15/ipch/AutoPCH/35af7c1ee7c32fee/MAIN.ipch b/level1/p12_warehouse/warehouse/.vs/warehouse/v15/ipch/AutoPCH/35af7c1ee7c32fee/MAIN.ipch new file mode 100644 index 00000000..b8d1451d Binary files /dev/null and b/level1/p12_warehouse/warehouse/.vs/warehouse/v15/ipch/AutoPCH/35af7c1ee7c32fee/MAIN.ipch differ diff --git a/level1/p12_warehouse/warehouse/Debug/warehouse.exe b/level1/p12_warehouse/warehouse/Debug/warehouse.exe new file mode 100644 index 00000000..e574d20d Binary files /dev/null and b/level1/p12_warehouse/warehouse/Debug/warehouse.exe differ diff --git a/level1/p12_warehouse/warehouse/Debug/warehouse.ilk b/level1/p12_warehouse/warehouse/Debug/warehouse.ilk new file mode 100644 index 00000000..2bf617a3 Binary files /dev/null and b/level1/p12_warehouse/warehouse/Debug/warehouse.ilk differ diff --git a/level1/p12_warehouse/warehouse/Debug/warehouse.pdb b/level1/p12_warehouse/warehouse/Debug/warehouse.pdb new file mode 100644 index 00000000..37c8a505 Binary files /dev/null and b/level1/p12_warehouse/warehouse/Debug/warehouse.pdb differ diff --git a/level1/p12_warehouse/warehouse/warehouse.sln b/level1/p12_warehouse/warehouse/warehouse.sln new file mode 100644 index 00000000..585a3927 --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse.sln @@ -0,0 +1,31 @@ +锘 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.572 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "warehouse", "warehouse\warehouse.vcxproj", "{FA2EEA43-1D6B-431D-A610-EC6229723FE2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FA2EEA43-1D6B-431D-A610-EC6229723FE2}.Debug|x64.ActiveCfg = Debug|x64 + {FA2EEA43-1D6B-431D-A610-EC6229723FE2}.Debug|x64.Build.0 = Debug|x64 + {FA2EEA43-1D6B-431D-A610-EC6229723FE2}.Debug|x86.ActiveCfg = Debug|Win32 + {FA2EEA43-1D6B-431D-A610-EC6229723FE2}.Debug|x86.Build.0 = Debug|Win32 + {FA2EEA43-1D6B-431D-A610-EC6229723FE2}.Release|x64.ActiveCfg = Release|x64 + {FA2EEA43-1D6B-431D-A610-EC6229723FE2}.Release|x64.Build.0 = Release|x64 + {FA2EEA43-1D6B-431D-A610-EC6229723FE2}.Release|x86.ActiveCfg = Release|Win32 + {FA2EEA43-1D6B-431D-A610-EC6229723FE2}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {516FC20C-7C77-404A-B955-074CF29D0773} + EndGlobalSection +EndGlobal diff --git a/level1/p12_warehouse/warehouse/warehouse/1.txt b/level1/p12_warehouse/warehouse/warehouse/1.txt new file mode 100644 index 00000000..6a08ee59 Binary files /dev/null and b/level1/p12_warehouse/warehouse/warehouse/1.txt differ diff --git a/level1/p12_warehouse/warehouse/warehouse/Debug/main.obj b/level1/p12_warehouse/warehouse/warehouse/Debug/main.obj new file mode 100644 index 00000000..228874d4 Binary files /dev/null and b/level1/p12_warehouse/warehouse/warehouse/Debug/main.obj differ diff --git a/level1/p12_warehouse/warehouse/warehouse/Debug/vc141.idb b/level1/p12_warehouse/warehouse/warehouse/Debug/vc141.idb new file mode 100644 index 00000000..c6309acd Binary files /dev/null and b/level1/p12_warehouse/warehouse/warehouse/Debug/vc141.idb differ diff --git a/level1/p12_warehouse/warehouse/warehouse/Debug/vc141.pdb b/level1/p12_warehouse/warehouse/warehouse/Debug/vc141.pdb new file mode 100644 index 00000000..299cb4b4 Binary files /dev/null and b/level1/p12_warehouse/warehouse/warehouse/Debug/vc141.pdb differ diff --git a/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.log b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.log new file mode 100644 index 00000000..f56e6e54 --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.log @@ -0,0 +1,2 @@ +锘 main.cpp + warehouse.vcxproj -> F:\coding\c2019\level1\p12_warehouse\warehouse\Debug\warehouse.exe diff --git a/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/CL.command.1.tlog b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/CL.command.1.tlog new file mode 100644 index 00000000..e7b978a3 Binary files /dev/null and b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/CL.command.1.tlog differ diff --git a/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/CL.read.1.tlog b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/CL.read.1.tlog new file mode 100644 index 00000000..f7cbe7de Binary files /dev/null and b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/CL.read.1.tlog differ diff --git a/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/CL.write.1.tlog b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/CL.write.1.tlog new file mode 100644 index 00000000..2b89f6af Binary files /dev/null and b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/CL.write.1.tlog differ diff --git a/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/link.command.1.tlog b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/link.command.1.tlog new file mode 100644 index 00000000..e4a6067c Binary files /dev/null and b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/link.command.1.tlog differ diff --git a/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/link.read.1.tlog b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/link.read.1.tlog new file mode 100644 index 00000000..6d46020d Binary files /dev/null and b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/link.read.1.tlog differ diff --git a/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/link.write.1.tlog b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/link.write.1.tlog new file mode 100644 index 00000000..b1c36526 Binary files /dev/null and b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/link.write.1.tlog differ diff --git a/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/warehouse.lastbuildstate b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/warehouse.lastbuildstate new file mode 100644 index 00000000..a402e9e0 --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse/Debug/warehouse.tlog/warehouse.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.17763.0 +Debug|Win32|F:\coding\c2019\level1\p12_warehouse\warehouse\| diff --git a/level1/p12_warehouse/warehouse/warehouse/main.cpp b/level1/p12_warehouse/warehouse/warehouse/main.cpp new file mode 100644 index 00000000..a9ef4fd7 --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse/main.cpp @@ -0,0 +1,184 @@ +#include +#include +#include +#include +#pragma warning(disable : 4996)//在VS里fopen没法直接使用,必须关掉警告 +typedef struct +{ + char name[100]; + int number; +}things; + +const int size = sizeof(things); +things goods[100]; + +void menu(); +void show_all(); +void getin(); +void remove(); + + +int main() +{ + char ch[100]; + while (1) + { + menu(); + gets_s(ch); + switch (ch[0]) + { + case '1':show_all(); break; + case '2':getin(); break; + case '3':remove(); break; + case '4':printf("Thank you for usage!"); system("pause"); exit(0); + default:printf("Wrong input.Please input your order again."); system("pause"); break; + } + system("pause"); + } +} +void menu() +{ + system("cls"); + printf("\t1:Show all things in the warehouse.\n"); + printf("\t2:Add things into the warehouse.\n"); + printf("\t3:Remove things from the warehouse.\n"); + printf("\t4:Exit this program.\n"); + printf("\tPlease input the number of order:"); + return; +} + +void show_all() +{ + FILE *fp; + int i=0, n = 0; + if ((fp = fopen("1.txt", "ab+")) == NULL) + { + printf("Error!Can't open the file!"); + return; + } + while (!feof(fp)) + { + if (fread(&goods[n], size, 1, fp)) + { + n++; + } + } + fclose(fp); + for (i = 0; i < n; i++) + { + printf("Name:%s\tNumber:%d\n", goods[i].name, goods[i].number); + } + return; +} + +void getin() +{ + FILE *fp; + int i = 0, n = 0; + char new_name[100]; + int new_number; + if ((fp = fopen("1.txt", "ab+")) == NULL) + { + printf("Error!Can't open the file!"); + return; + } + while (!feof(fp)) + { + if (fread(&goods[n], size, 1, fp)) + { + n++; + } + } + fclose(fp); + if ((fp = fopen("1.txt", "wb+")) == NULL) + { + printf("ERROR!Can't open the FILE."); + return; + } + + printf("Input the name:"); + gets_s(new_name); + printf("Input the number:"); + scanf_s("%d", &new_number); + for (i = 0; i < n; i++) + { + if (strcmp(goods[i].name, new_name) == 0) + { + goods[i].number += new_number; + for (i = 0; i < n; i++) + { + fwrite(&goods[i], size, 1, fp); + } + fclose(fp); + return; + } + } + strcpy(goods[n].name, new_name); + goods[n].number = new_number; + n++; + for (i = 0; i < n; i++) + { + fwrite(&goods[i], size, 1, fp); + } + fclose(fp); +} + +void remove() +{ + FILE *fp; + int i = 0, n = 0; + char new_name[100]; + int new_number; + if ((fp = fopen("1.txt", "ab+")) == NULL) + { + printf("Error!Can't open the file!"); + return; + } + while (!feof(fp)) + { + if (fread(&goods[n], size, 1, fp)) + { + n++; + } + } + fclose(fp); + if ((fp = fopen("1.txt", "wb+")) == NULL) + { + printf("ERROR!Can't open the FILE."); + return; + } + + printf("Input the name:"); + gets_s(new_name); + printf("Input the number:"); + scanf_s("%d", &new_number); + for (i = 0; i < n; i++) + { + if (strcmp(goods[i].name, new_name) == 0) + { + if (goods[i].number >= new_number) + { + goods[i].number -= new_number; + for (i = 0; i < n; i++) + { + fwrite(&goods[i], size, 1, fp); + } + fclose(fp); + return; + } + else + { + break; + } + } + } + for (i = 0; i < n; i++) + { + fwrite(&goods[i], size, 1, fp); + } + fclose(fp); + return; + printf("Wrong!Please act again!"); + +} + diff --git a/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj b/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj new file mode 100644 index 00000000..b27b41f7 --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj @@ -0,0 +1,123 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {FA2EEA43-1D6B-431D-A610-EC6229723FE2} + warehouse + 10.0.17763.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + + \ No newline at end of file diff --git a/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj.filters b/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj.filters new file mode 100644 index 00000000..048f37d5 --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj.filters @@ -0,0 +1,22 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 婧愭枃浠 + + + \ No newline at end of file diff --git a/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj.user b/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj.user new file mode 100644 index 00000000..be250787 --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj.user @@ -0,0 +1,4 @@ +锘 + + + \ No newline at end of file diff --git "a/level1/\344\272\224\345\255\220\346\243\213/Project1" "b/level1/\344\272\224\345\255\220\346\243\213/Project1" new file mode 160000 index 00000000..fd5fce14 --- /dev/null +++ "b/level1/\344\272\224\345\255\220\346\243\213/Project1" @@ -0,0 +1 @@ +Subproject commit fd5fce145c2f9eba78933a25747f04a51f4affe6 diff --git "a/level1/\344\272\224\345\255\220\346\243\213/\344\272\224\345\255\220\346\243\213\350\247\204\345\210\231\347\256\200\344\273\213.txt" "b/level1/\344\272\224\345\255\220\346\243\213/\344\272\224\345\255\220\346\243\213\350\247\204\345\210\231\347\256\200\344\273\213.txt" new file mode 100644 index 00000000..e69de29b diff --git "a/level1/\344\272\224\345\255\220\346\243\213/\345\244\247\351\241\271\347\233\256\347\232\204\347\273\217\351\252\214.txt" "b/level1/\344\272\224\345\255\220\346\243\213/\345\244\247\351\241\271\347\233\256\347\232\204\347\273\217\351\252\214.txt" new file mode 100644 index 00000000..e64f7941 --- /dev/null +++ "b/level1/\344\272\224\345\255\220\346\243\213/\345\244\247\351\241\271\347\233\256\347\232\204\347\273\217\351\252\214.txt" @@ -0,0 +1,7 @@ +1、拆成小项目来做 +2、计划安排: +(1) 画出棋盘 +(2)让人可以走棋 +(3)可以随机下棋的AI +(4)可以估值 +(5)剪枝,去除不可能的情况 \ No newline at end of file