diff --git a/level1/p01_runningLetter/RunningLetter.cpp b/level1/p01_runningLetter/RunningLetter.cpp new file mode 100644 index 00000000..c9799c24 --- /dev/null +++ b/level1/p01_runningLetter/RunningLetter.cpp @@ -0,0 +1,43 @@ +// RunningLetter.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// + +#include +#include + +int main() +{ + char a; + scanf_s("%c", &a); + for (int i = 1; i <= 118; i++) + { + system("cls"); + for (int j = 0; j <= i; j++) + { + printf(" "); + } + printf("%c", a); + Sleep(10); + } + for (int p = 118; p >= 1; p--) + { + system("cls"); + for (int x = 0; x <= p; x++) + { + printf(" "); + } + printf("%c", a); + Sleep(10); + } + return 0; +} + +// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 +// 调试程序: F5 或调试 >“开始调试”菜单 + +// 入门使用技巧: +// 1. 使用解决方案资源管理器窗口添加/管理文件 +// 2. 使用团队资源管理器窗口连接到源代码管理 +// 3. 使用输出窗口查看生成输出和其他消息 +// 4. 使用错误列表窗口查看错误 +// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 +// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 diff --git a/level1/p03_Diophantus/Diophantus.cpp b/level1/p03_Diophantus/Diophantus.cpp new file mode 100644 index 00000000..32920fff --- /dev/null +++ b/level1/p03_Diophantus/Diophantus.cpp @@ -0,0 +1,28 @@ +// Diophantus.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// + +#include + +int main() +{ + int x, y; + for (x = 28; x <= 120; x=x+28) + { + y=x/2; + if (x - y == x * 11 / 28 +9 ) + break; + } + printf("%d", x-4); + return 0; +} + +// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 +// 调试程序: F5 或调试 >“开始调试”菜单 + +// 入门使用技巧: +// 1. 使用解决方案资源管理器窗口添加/管理文件 +// 2. 使用团队资源管理器窗口连接到源代码管理 +// 3. 使用输出窗口查看生成输出和其他消息 +// 4. 使用错误列表窗口查看错误 +// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 +// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 diff --git a/level1/p04_ narcissus/narcissus.cpp b/level1/p04_ narcissus/narcissus.cpp new file mode 100644 index 00000000..ae530666 --- /dev/null +++ b/level1/p04_ narcissus/narcissus.cpp @@ -0,0 +1,27 @@ +// narcissus.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// + +#include +#include + +int main() +{ + int x; + for (x = 100; x <= 999; x++) + { + if (x == pow(x % 10, 3) + pow(x / 10 % 10,3)+pow(x/100%10,3)) + printf("%d\n",x); + } + return 0; +} + +// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 +// 调试程序: F5 或调试 >“开始调试”菜单 + +// 入门使用技巧: +// 1. 使用解决方案资源管理器窗口添加/管理文件 +// 2. 使用团队资源管理器窗口连接到源代码管理 +// 3. 使用输出窗口查看生成输出和其他消息 +// 4. 使用错误列表窗口查看错误 +// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 +// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 diff --git a/level1/p05_allPrimes/allPrimes.cpp b/level1/p05_allPrimes/allPrimes.cpp new file mode 100644 index 00000000..3e0460bd --- /dev/null +++ b/level1/p05_allPrimes/allPrimes.cpp @@ -0,0 +1,37 @@ +// allPrimes.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// + +#include +#include +#include + +int main() +{ + int p,x; + double a, b; + a = clock(); + for (p = 2; p <= 1000; p++) + { + x = 0; + for (int i = 2; i <= sqrt(p); i++) + { + if (p % i == 0) + x++; + } + if (x == 0) printf("%d\n", p); + } + b = clock(); + printf("运行时间为%.3fs", (b-a)/1000); + return 0; +} + +// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 +// 调试程序: F5 或调试 >“开始调试”菜单 + +// 入门使用技巧: +// 1. 使用解决方案资源管理器窗口添加/管理文件 +// 2. 使用团队资源管理器窗口连接到源代码管理 +// 3. 使用输出窗口查看生成输出和其他消息 +// 4. 使用错误列表窗口查看错误 +// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 +// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 diff --git a/level1/p06_Goldbach/narcissus.cpp b/level1/p06_Goldbach/narcissus.cpp new file mode 100644 index 00000000..ae530666 --- /dev/null +++ b/level1/p06_Goldbach/narcissus.cpp @@ -0,0 +1,27 @@ +// narcissus.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// + +#include +#include + +int main() +{ + int x; + for (x = 100; x <= 999; x++) + { + if (x == pow(x % 10, 3) + pow(x / 10 % 10,3)+pow(x/100%10,3)) + printf("%d\n",x); + } + return 0; +} + +// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 +// 调试程序: F5 或调试 >“开始调试”菜单 + +// 入门使用技巧: +// 1. 使用解决方案资源管理器窗口添加/管理文件 +// 2. 使用团队资源管理器窗口连接到源代码管理 +// 3. 使用输出窗口查看生成输出和其他消息 +// 4. 使用错误列表窗口查看错误 +// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 +// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 diff --git a/level1/p07_encrypt_decrypt/encrypt_decrypt.cpp b/level1/p07_encrypt_decrypt/encrypt_decrypt.cpp new file mode 100644 index 00000000..bab7e1af --- /dev/null +++ b/level1/p07_encrypt_decrypt/encrypt_decrypt.cpp @@ -0,0 +1,56 @@ +// encrypt_decrypt.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// + +#include +#include + +int main() +{ + char a[10],e[100],d[100]; + gets_s(a,10); + if (strcmp(a, "encrypt") == 0) + { + printf("please input your string:\n"); + gets_s(e, 100); + for (int i = 0; i <= 99; i++) + { + if ((e[i] >= 65 && e[i] <= 86) || (e[i] >= 97 && e[i] <= 118)) + e[i] = e[i] + 4; + else + if ((e[i] >= 87 && e[i] <= 90) || e[i] >= 119 && e[i] <= 122) + e[i] = e[i] - 22; + } + puts(e); + } + else + { + if (strcmp(a, "decrypt") == 0) + { + printf("please input your string:\n"); + gets_s(d, 100); + for (int j = 0; j <= 99; j++) + { + if ((d[j] >= 69 && d[j] <= 90) || (d[j] >= 101 && d[j] <= 122)) + d[j] = d[j] - 4; + else + if ((d[j] >= 65 && d[j] <= 68) || d[j] >= 97 && d[j] <= 100) + d[j] = d[j] + 22; + } + puts(d); + } + else + printf("error"); + } + return 0; +} + +// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 +// 调试程序: F5 或调试 >“开始调试”菜单 + +// 入门使用技巧: +// 1. 使用解决方案资源管理器窗口添加/管理文件 +// 2. 使用团队资源管理器窗口连接到源代码管理 +// 3. 使用输出窗口查看生成输出和其他消息 +// 4. 使用错误列表窗口查看错误 +// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 +// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 diff --git a/level1/p08_hanoi/hanoi.cpp b/level1/p08_hanoi/hanoi.cpp new file mode 100644 index 00000000..db85e68a --- /dev/null +++ b/level1/p08_hanoi/hanoi.cpp @@ -0,0 +1,30 @@ +#include + +void hanoi(int n, char a, char b, char c); +void move(char from, char to); +int main() +{ + int n; + scanf_s("%d", &n); + hanoi(n, 'A', 'B', 'C'); + return 0; +} +void hanoi(int n, char a, char b, char c) +{ + if (n == 1) + { + move(a, c); + } + else + { + hanoi(n - 1, a, c, b); + move(a, c); + hanoi(n - 1, b, a, c); + return; + } +} +void move(char from, char to) +{ + printf("%c->%c\n", from, to); + return; +} \ No newline at end of file diff --git a/level1/p09_maze/maze.cpp b/level1/p09_maze/maze.cpp new file mode 100644 index 00000000..e4e6c46b --- /dev/null +++ b/level1/p09_maze/maze.cpp @@ -0,0 +1,105 @@ + + +#include +#include +#include + + +int main() +{ + char maze[10][20] = + { {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'}, + {'#','O','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ',' ','#',' ',' ','#'}, + {'#',' ','#',' ','#','#','#','#','#','#',' ','#','#','#',' ',' ',' ',' ',' ','#'}, + {'#',' ',' ',' ',' ',' ','#',' ',' ','#',' ','#',' ','#',' ','#','#','#',' ','#'}, + {'#','#','#','#',' ',' ','#',' ',' ','#',' ','#',' ','#',' ','#',' ','#',' ','#'}, + {'#',' ',' ',' ',' ','#','#',' ',' ','#',' ',' ',' ','#',' ','#',' ','#',' ','#'}, + {'#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#',' ','#'}, + {'#','#','#','#',' ',' ',' ','#',' ','#','#','#','#',' ','#',' ',' ','#',' ','#'}, + {'#',' ',' ',' ',' ',' ',' ','#','#',' ',' ',' ',' ',' ','#','#','#',' ',' ',' '}, + {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#' } +}; + char *p=&maze[1][1],direction; + while (maze[8][19] != 'O') + { + system("cls"); + for (int i = 0; i <= 9; i++) + { + for (int j = 0; j <= 19; j++) + { + printf("%c", maze[i][j]); + } + printf("\n"); + } + direction = _getch(); + switch (direction) + { + case 'w': + { + if (*(p - 20) == ' ') + { + *p = ' '; + p-=20; + *p = 'O'; + break; + } + else + break; + } + { + + } + case 'a': + { + if (*(p - 1) == ' ') + { + *p = ' '; + p--; + *p = 'O'; + break; + } + else + break; + } + case 's': + { + if (*(p + 20) == ' ') + { + *p = ' '; + p += 20; + *p = 'O'; + break; + } + else + break; + } + case 'd': + { + if (*(p + 1) == ' ') + { + *p = ' '; + p++; + *p = 'O'; + break; + } + else + break; + } + } + } + system("cls"); + for (int i = 0; i <= 9; i++) + { + for (int j = 0; j <= 19; j++) + { + printf("%c", maze[i][j]); + } + printf("\n"); + } + printf("\nYou win!\n"); + return 0; +} + + + + diff --git a/level1/p10_pushBoxes/pushBoxes/pushBoxes.sln b/level1/p10_pushBoxes/pushBoxes/pushBoxes.sln new file mode 100644 index 00000000..31bba18d --- /dev/null +++ b/level1/p10_pushBoxes/pushBoxes/pushBoxes.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31105.61 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pushBoxes", "pushBoxes\pushBoxes.vcxproj", "{574A989A-A0DE-4E10-A775-F329CA583623}" +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 + {574A989A-A0DE-4E10-A775-F329CA583623}.Debug|x64.ActiveCfg = Debug|x64 + {574A989A-A0DE-4E10-A775-F329CA583623}.Debug|x64.Build.0 = Debug|x64 + {574A989A-A0DE-4E10-A775-F329CA583623}.Debug|x86.ActiveCfg = Debug|Win32 + {574A989A-A0DE-4E10-A775-F329CA583623}.Debug|x86.Build.0 = Debug|Win32 + {574A989A-A0DE-4E10-A775-F329CA583623}.Release|x64.ActiveCfg = Release|x64 + {574A989A-A0DE-4E10-A775-F329CA583623}.Release|x64.Build.0 = Release|x64 + {574A989A-A0DE-4E10-A775-F329CA583623}.Release|x86.ActiveCfg = Release|Win32 + {574A989A-A0DE-4E10-A775-F329CA583623}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C5086666-B2B4-4D5C-94B1-455AB3488F44} + EndGlobalSection +EndGlobal diff --git a/level1/p10_pushBoxes/pushBoxes/pushBoxes/map1.txt b/level1/p10_pushBoxes/pushBoxes/pushBoxes/map1.txt new file mode 100644 index 00000000..6f170f89 --- /dev/null +++ b/level1/p10_pushBoxes/pushBoxes/pushBoxes/map1.txt @@ -0,0 +1 @@ + ### #X# # #######O OX##X OI#######O# #X# ### \ No newline at end of file diff --git a/level1/p10_pushBoxes/pushBoxes/pushBoxes/map2.txt b/level1/p10_pushBoxes/pushBoxes/pushBoxes/map2.txt new file mode 100644 index 00000000..8a4daa3b --- /dev/null +++ b/level1/p10_pushBoxes/pushBoxes/pushBoxes/map2.txt @@ -0,0 +1 @@ + #### #XX# ## X## # OX# ## O ### #OO ## I ######### \ No newline at end of file diff --git a/level1/p10_pushBoxes/pushBoxes/pushBoxes/pushBoxes.cpp b/level1/p10_pushBoxes/pushBoxes/pushBoxes/pushBoxes.cpp new file mode 100644 index 00000000..14505074 --- /dev/null +++ b/level1/p10_pushBoxes/pushBoxes/pushBoxes/pushBoxes.cpp @@ -0,0 +1,169 @@ +// pushBoxes.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// + +#include +#include +#include + +void printmap(char *p); +int main() +{ + int score = 100, step = 0, time = 1; + char direction; + char* man, * position[4]; + int n; + printf("Please enter '1' or '2' to choose map\npress w a s d to move\n"); + scanf_s("%d", &n); //选择地图 + FILE* loadmap; + char map[8][8] = { 0 }; + switch (n) + { + case 1: + { + freopen_s(&loadmap, "map1.txt", "r", stdin); + position[0] = &map[1][3]; position[1] = &map[3][6]; position[2] = &map[4][1]; position[3] = &map[6][4]; + man = &map[4][4];//指针分别指向地点、人物 + break; + } + case 2: + { + freopen_s(&loadmap, "map2.txt", "r", stdin); + position[0] = &map[1][3]; position[1] = &map[1][4]; position[2] = &map[2][4]; position[3] = &map[3][5]; + man = &map[6][3];//指针分别指向地点、人物 + break; + } + default:return -1; + } + for (int i = 0; i <= 7; i++) + { + for (int j = 0; j <= 7; j++) + scanf_s("%c", &map[i][j], 1); + }//加载地图 + + + //开始游玩 + while ('O' != *position[0] || 'O' != *position[1] || 'O' != *position[2] || 'O' != *position[3]) + { + system("cls"); + printmap(map[0]); + printf("\n\nscore:%d,step:%d", score, step); + switch (direction = _getch()) + { + case 'w': + { + if (*(man - 8) == ' ' || *(man - 8) == 'X') + { + *man = ' '; man -= 8; *man = 'I'; score--; step++; + } + else + { + if (*(man - 8) == 'O' && (*(man - 16) == ' ') || *(man - 16) == 'X') + { + *man = ' '; man -= 8; *man = 'I'; *(man - 8) = 'O'; score--; step++; + } + else break; + } + for (int i = 0; i <= 3; i++) + { + if (*position[i] == ' ') + *position[i] = 'X'; + } + break; + } + case 'a': + { + if (*(man - 1) == ' ' || *(man - 1) == 'X') + { + *man = ' '; man -= 1; *man = 'I'; score--; step++; + } + else + { + if (*(man - 1) == 'O' && (*(man - 2) == ' ') || *(man - 2) == 'X') + { + *man = ' '; man -= 1; *man = 'I'; *(man - 1) = 'O'; score--; step++; + } + else break; + } + for (int i = 0; i <= 3; i++) + { + if (*position[i] == ' ') + *position[i] = 'X'; + } + break; + } + case 's': + { + if (*(man + 8) == ' ' || *(man + 8) == 'X') + { + *man = ' '; man += 8; *man = 'I'; score--; step++; + } + else + { + if (*(man + 8) == 'O' && (*(man + 16) == ' ') || *(man + 16) == 'X') + { + *man = ' '; man += 8; *man = 'I'; *(man + 8) = 'O'; score--; step++; + } + else break; + } + for (int i = 0; i <= 3; i++) + { + if (*position[i] == ' ') + *position[i] = 'X'; + } + break; + } + case 'd': + { + if (*(man + 1) == ' ' || *(man + 1) == 'X') + { + *man = ' '; man += 1; *man = 'I'; score--; step++; + } + else + { + if (*(man + 1) == 'O' && (*(man + 2) == ' ') || *(man + 2) == 'X') + { + *man = ' '; man += 1; *man = 'I'; *(man + 1) = 'O'; score--; step++; + } + else break; + } + for (int i = 0; i <= 3; i++) + { + if (*position[i] == ' ') + *position[i] = 'X'; + } + break; + } + } + } + system("cls"); + printmap(map[0]); + printf("you win"); + if (n == 1) + { + freopen_s(&loadmap, "score1.txt", "a", stdout); + } + if (n == 2) + { + freopen_s(&loadmap, "score2.txt", "a", stdout); + } + printf("\nYour score is:%d", score); + system("pause"); + if (loadmap != NULL) + fclose(loadmap); + return 0; +} + +//打印地图的函数 +void printmap(char* p) +{ + for (int i = 0; i <= 7; i++) + { + for (int j = 0; j <= 7; j++) + { + printf("%c", *p); p++; + } + printf("\n"); + } + return; +} + diff --git a/level1/p10_pushBoxes/pushBoxes/pushBoxes/pushBoxes.vcxproj b/level1/p10_pushBoxes/pushBoxes/pushBoxes/pushBoxes.vcxproj new file mode 100644 index 00000000..b84f2ca4 --- /dev/null +++ b/level1/p10_pushBoxes/pushBoxes/pushBoxes/pushBoxes.vcxproj @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {574a989a-a0de-4e10-a775-f329ca583623} + pushBoxes + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/level1/p10_pushBoxes/pushBoxes/pushBoxes/pushBoxes.vcxproj.filters b/level1/p10_pushBoxes/pushBoxes/pushBoxes/pushBoxes.vcxproj.filters new file mode 100644 index 00000000..a76f839c --- /dev/null +++ b/level1/p10_pushBoxes/pushBoxes/pushBoxes/pushBoxes.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;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/pushBoxes/pushBoxes/pushBoxes.vcxproj.user b/level1/p10_pushBoxes/pushBoxes/pushBoxes/pushBoxes.vcxproj.user new file mode 100644 index 00000000..88a55094 --- /dev/null +++ b/level1/p10_pushBoxes/pushBoxes/pushBoxes/pushBoxes.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/level1/p10_pushBoxes/pushBoxes/pushBoxes/score1.txt b/level1/p10_pushBoxes/pushBoxes/pushBoxes/score1.txt new file mode 100644 index 00000000..9150617c --- /dev/null +++ b/level1/p10_pushBoxes/pushBoxes/pushBoxes/score1.txt @@ -0,0 +1,11 @@ +밴. . . + +Your score is:79밴. . . + +Your score is:89밴. . . + +Your score is:89밴. . . + +Your score is:89밴. . . + +Your score is:89 \ No newline at end of file diff --git a/level1/p10_pushBoxes/pushBoxes/pushBoxes/score2.txt b/level1/p10_pushBoxes/pushBoxes/pushBoxes/score2.txt new file mode 100644 index 00000000..e69de29b diff --git a/level1/p11_linkedList/linkedlist.cpp b/level1/p11_linkedList/linkedlist.cpp new file mode 100644 index 00000000..19fcd990 --- /dev/null +++ b/level1/p11_linkedList/linkedlist.cpp @@ -0,0 +1,138 @@ +// linkedlist.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// +#include +#include + +struct link +{ + int data; + struct link* next; +}; + +link* createlink(int n) +{ + link* head = (link*)malloc(sizeof(link)); + link* temp = head; + for (int i = 1; i <= n; i++) + { + link* node = (link*)malloc(sizeof(link)); + if (node!=NULL&&temp!=NULL) + { + scanf_s("%d", &(node->data)); + temp->next = node; + node->next = NULL; + temp = temp->next; + } + } + return head; +} + + +link* fanxu(link* p); +void xianshi(link* p); +int searchnode(link* p,int a); +int searchnext(link* p, int a,int x); + +int main() +{ + int n; + scanf_s("%d", &n); + link* p = createlink(n); + int number; + scanf_s("%d", &number); + link* temp = p->next; + while (temp!= NULL) + { + printf("%d ", temp->data); + temp = temp->next; + } + p = fanxu(p); + temp = p; + printf("\n"); + while (temp != NULL) + { + printf("%d ", temp->data); + temp = temp->next; + } + int position = searchnode(p, number); + printf("\n%d", position); + int next = searchnext(p, position,number); + printf("\n%d", next); +} + +void xianshi(link* p) +{ + link* temp=p; + while (temp->next!= NULL) + { + temp = temp->next; + printf("%d ", temp->data); + } +} + +link* fanxu(link* p) +{ + int i = 0; + link* temp[3] = { p,p->next,p->next->next }; + while (temp[0]->next != NULL && temp[1]->next != NULL && temp[2]->next != NULL) + { + temp[(i + 1) % 3]->next = temp[i % 3]; + temp[i % 3] = temp[(i + 2) % 3]->next; + i++; + } + temp[(i + 1) % 3]->next = temp[i % 3]; + temp[(i + 2) % 3]->next = temp[(i+1) % 3]; + p->next->next = NULL; + p= NULL; + return temp[(i + 2) % 3]; + } + +int searchnode(link* p,int a) +{ + int n = 1; + link* temp = p; + while (temp != NULL) + { + if (temp->data == a) + { + return n; + } + else + { + temp = temp->next; + n++; + } + } + return -1; +} + +int searchnext(link* p, int a,int x) +{ + link* temp = p; + int n = a+1; + for (int i = 1; i <= a; i++) + { + temp = temp->next; + } + while (temp != NULL) + { + if (temp->data == x) + return n; + else + { + temp = temp->next; + n++; + } + } + return -1; +} +// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 +// 调试程序: F5 或调试 >“开始调试”菜单 + +// 入门使用技巧: +// 1. 使用解决方案资源管理器窗口添加/管理文件 +// 2. 使用团队资源管理器窗口连接到源代码管理 +// 3. 使用输出窗口查看生成输出和其他消息 +// 4. 使用错误列表窗口查看错误 +// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 +// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 diff --git a/level1/p12_warehouse/warehouse/warehouse.sln b/level1/p12_warehouse/warehouse/warehouse.sln new file mode 100644 index 00000000..ed70828a --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31105.61 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "warehouse", "warehouse\warehouse.vcxproj", "{D9D2861C-EC0D-4A30-AD7A-99B230A78ED5}" +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 + {D9D2861C-EC0D-4A30-AD7A-99B230A78ED5}.Debug|x64.ActiveCfg = Debug|x64 + {D9D2861C-EC0D-4A30-AD7A-99B230A78ED5}.Debug|x64.Build.0 = Debug|x64 + {D9D2861C-EC0D-4A30-AD7A-99B230A78ED5}.Debug|x86.ActiveCfg = Debug|Win32 + {D9D2861C-EC0D-4A30-AD7A-99B230A78ED5}.Debug|x86.Build.0 = Debug|Win32 + {D9D2861C-EC0D-4A30-AD7A-99B230A78ED5}.Release|x64.ActiveCfg = Release|x64 + {D9D2861C-EC0D-4A30-AD7A-99B230A78ED5}.Release|x64.Build.0 = Release|x64 + {D9D2861C-EC0D-4A30-AD7A-99B230A78ED5}.Release|x86.ActiveCfg = Release|Win32 + {D9D2861C-EC0D-4A30-AD7A-99B230A78ED5}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8D6C990E-8C38-415F-9740-13B9AF0D66E8} + EndGlobalSection +EndGlobal diff --git a/level1/p12_warehouse/warehouse/warehouse/test.txt b/level1/p12_warehouse/warehouse/warehouse/test.txt new file mode 100644 index 00000000..00ca4852 --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse/test.txt @@ -0,0 +1,4 @@ +3 +100114514 shangpin1 62 +101919810 shangpin2 53 +100010086 shangpin3 49 diff --git a/level1/p12_warehouse/warehouse/warehouse/warehouse.cpp b/level1/p12_warehouse/warehouse/warehouse/warehouse.cpp new file mode 100644 index 00000000..91a5a07a --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse/warehouse.cpp @@ -0,0 +1,112 @@ +// warehouse.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// + +#include +#include +#include + +struct item +{ + int quantity;//数量 + char name[20];//商品名 + long number;//编号 +}; + +void showlist(item* a); + +int main() +{ + int n,num; + long in, out; + FILE* p; + freopen_s(&p, "test.txt", "r", stdin); + scanf_s("%d\n", &n); + struct item a[3]; + for (int i = 0; i < n; i++) + { + scanf_s("%ld %s %d\n",&a[i].number, &(a[i].name),20,&a[i].quantity); + } + restart:system("cls"); + printf("请按以下数字执行操作:\n1.显示存货列表\n2.入库\n3.出库\n4.退出程序\n"); + menu:switch (int x = _getch()) + { + case '1': + { + system("cls"); + printf("商品列表:\n"); + showlist(a); + printf("按x返回,按其余键结束程序"); + break; + } + case '2': + { + system("cls"); + showlist(a); + printf("请输入需要入库的商品编号和数量\n如:100114514 3\n"); + freopen_s(&p, "CON", "r", stdin); + scanf_s("%ld %d", &in,&num); + for (int i = 0; i < n; i++) + { + if (in == a[i].number) + { + a[i].quantity = a[i].quantity + num; + break; + } + } + freopen_s(&p, "test.txt", "w", stdout); + printf("%d\n", n); + showlist(a); + return 0; + } + case '3': + { + system("cls"); + showlist(a); + printf("请输入需要出库的商品编号和数量\n如:100114514 3\n"); + freopen_s(&p, "CON", "r", stdin); + scanf_s("%ld %d", &in, &num); + for (int i = 0; i < n; i++) + { + if (in == a[i].number) + { + a[i].quantity = a[i].quantity - num; + break; + } + } + freopen_s(&p, "test.txt", "w", stdout); + printf("%d\n", n); + showlist(a); + return 0; + } + case '4': + { + return 0; + } + default:goto menu; + } + if (_getch() == 'x') + { + goto restart; + } +} + +void showlist(item* a) +{ + for (int i = 0; i < 3; i++) + { + printf("%ld %s %d\n", a->number,a->name,a->quantity); + a++; + } + return; +} + +// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 +// 调试程序: F5 或调试 >“开始调试”菜单 + +// 入门使用技巧: +// 1. 使用解决方案资源管理器窗口添加/管理文件 +// 2. 使用团队资源管理器窗口连接到源代码管理 +// 3. 使用输出窗口查看生成输出和其他消息 +// 4. 使用错误列表窗口查看错误 +// 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 +// 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 diff --git a/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj b/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj new file mode 100644 index 00000000..f83e482a --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj @@ -0,0 +1,147 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {d9d2861c-ec0d-4a30-ad7a-99b230a78ed5} + warehouse + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + 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..b23924c0 --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;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..88a55094 --- /dev/null +++ b/level1/p12_warehouse/warehouse/warehouse/warehouse.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file