From 0a191f5a781067dd02916f1f7bf6af37ec07a853 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Sun, 11 Mar 2018 17:05:34 +0800 Subject: [PATCH 01/29] none --- level1/p01_runningLetter/runningLetter.c | 35 ++++++++++++++++++++++++ level1/p02_isPrime/isPrime.c | 25 +++++++++++++++++ level1/p03_Diophantus/Diophantus.c | 21 ++++++++++++++ level1/p04_ narcissus/narcissus.c | 20 ++++++++++++++ level1/p05_allPrimes/allPrimes.c | 21 ++++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 level1/p01_runningLetter/runningLetter.c create mode 100644 level1/p02_isPrime/isPrime.c create mode 100644 level1/p03_Diophantus/Diophantus.c create mode 100644 level1/p04_ narcissus/narcissus.c create mode 100644 level1/p05_allPrimes/allPrimes.c diff --git a/level1/p01_runningLetter/runningLetter.c b/level1/p01_runningLetter/runningLetter.c new file mode 100644 index 00000000..219e6750 --- /dev/null +++ b/level1/p01_runningLetter/runningLetter.c @@ -0,0 +1,35 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#define screen_l 50 + +int main() +{ + system("mode con cols=50 lines=20"); + int l_w; + char words[36]; + scanf("%s", &words); + l_w = strlen(words); + for (int space_l = 0; space_l <= screen_l - l_w; space_l++) + { + for (int n = 0; n < space_l; n++) + { + printf(" "); + } + printf("%s", words); + Sleep(100); + system("CLS"); + } + for (int space_l = screen_l - l_w; space_l > 0; space_l--) + { + for (int n = space_l; n > 0; n--) + { + printf(" "); + } + printf("%s", words); + Sleep(100); + system("CLS"); + } + return 0; +} \ No newline at end of file diff --git a/level1/p02_isPrime/isPrime.c b/level1/p02_isPrime/isPrime.c new file mode 100644 index 00000000..b1b42719 --- /dev/null +++ b/level1/p02_isPrime/isPrime.c @@ -0,0 +1,25 @@ +#define _CRT_SECURE_NO_WARNINGS +#include + +void main() +{ + long long int input_n; + scanf("%lld", &input_n); + if (input_n == 1) + { + printf("The number is not a Prime.\n"); + goto bottom; + } + for (int n = 2; n*n <= input_n; n++) + { + if (input_n%n == 0) + { + printf("The number is not a Prime.\n"); + goto bottom; + } + } + printf("The number is a Prime.\n"); +bottom: + getchar(); + getchar(); +} \ No newline at end of file diff --git a/level1/p03_Diophantus/Diophantus.c b/level1/p03_Diophantus/Diophantus.c new file mode 100644 index 00000000..af088117 --- /dev/null +++ b/level1/p03_Diophantus/Diophantus.c @@ -0,0 +1,21 @@ +#define _CRT_SECURE_NO_WARNINGS +#include + +void main() +{ + int d_age; + int s_age; + for (int n = 1; n < 1000; n++) + { + if (n % 12 == 0) + if (n % 7 == 0) + { + s_age = 5 + (n / 12) + (n / 7) + (n / 6); + d_age = s_age * 2; + break; + } + } + printf("Diophantus is %d years old.", d_age); + getchar(); + getchar(); +} \ No newline at end of file diff --git a/level1/p04_ narcissus/narcissus.c b/level1/p04_ narcissus/narcissus.c new file mode 100644 index 00000000..694785ec --- /dev/null +++ b/level1/p04_ narcissus/narcissus.c @@ -0,0 +1,20 @@ +#define _CRT_SECURE_NO_WARNINGS +#include + +int power(int num, int times); + +void main() +{ + int p1, p2, p3; + for (int n=100; n < 1000; n++) + { + p1 = n % 10; + p2 = (n % 100) / 10; + p3 = (n - p1 - p2) / 100; + if (n == p1 * p1*p1 + p2 * p2*p2 + p3 * p3*p3) + { + printf("%d\n", n); + } + } + getchar(); +} \ No newline at end of file diff --git a/level1/p05_allPrimes/allPrimes.c b/level1/p05_allPrimes/allPrimes.c new file mode 100644 index 00000000..ad561189 --- /dev/null +++ b/level1/p05_allPrimes/allPrimes.c @@ -0,0 +1,21 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include + +void main() +{ + printf("2\n3\n4\n"); + for (int i = 2; i <= 1000; i++) + { + for (int n = 2; n*n <= i; n++) + { + if (i%n == 0) + break; + else if ((n+1)*(n+1) > i) + printf("%d\n", i); + } + } + printf("total time is:%ld ms",clock()); + getchar(); +} \ No newline at end of file From 55180a4eba04803294da2224c6e39134cd5aab82 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Sun, 11 Mar 2018 21:13:13 +0800 Subject: [PATCH 02/29] none --- level1/p06_Goldbach/Goldbach.c | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 level1/p06_Goldbach/Goldbach.c diff --git a/level1/p06_Goldbach/Goldbach.c b/level1/p06_Goldbach/Goldbach.c new file mode 100644 index 00000000..687d51c6 --- /dev/null +++ b/level1/p06_Goldbach/Goldbach.c @@ -0,0 +1,51 @@ +#define _CRT_SECURE_NO_WARNINGS +#include + +int primes(int *prime); + +void main() +{ + int n_prime = 26; //100有25个质数和1 + int prime[26]; + primes(prime); + for (int n = 3; n <= 100; n++) + { + for (int n1 = 0; n1 < 26; n1++) + { + for (int n2 = 1; n2 < 26; n2++) + { + if (prime[n1] + prime[n2] == n) + { + printf("%d = %d + %d\n", n, prime[n1], prime[n2]); + } + else if (prime[n1] + prime[n2] > n) + { + break; + } + } + } + } + getchar(); +} + +int primes(int *prime) +{ + prime[0] = 1; + prime[1] = 2; + prime[2] = 3; + int n_p=3; + for (int ni = 2; ni <= 100; ni++) + { + for (int i = 2; i*i <= ni; i++) + { + if (ni%i == 0) + break; + else if ((i + 1)*(i + 1) > ni && (i + 1)*(i + 1) != ni) + { + prime[n_p] = ni; + n_p++; + break; + } + } + } +} \ No newline at end of file From f852a1ef0dbe94e61fefc0c1a3c4d3322e7d44c5 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Sun, 11 Mar 2018 21:45:07 +0800 Subject: [PATCH 03/29] none --- level1/p06_Goldbach/Goldbach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/level1/p06_Goldbach/Goldbach.c b/level1/p06_Goldbach/Goldbach.c index 687d51c6..2983a0a5 100644 --- a/level1/p06_Goldbach/Goldbach.c +++ b/level1/p06_Goldbach/Goldbach.c @@ -5,7 +5,7 @@ int primes(int *prime); void main() { - int n_prime = 26; //100有25个质数和1 + int n_prime = 26; //100鍐呮湁25涓川鏁板拰璇佹槑鎵闇鐢ㄥ埌鐨1 int prime[26]; primes(prime); for (int n = 3; n <= 100; n++) From a2d35904fc8e428a52b3539c1c944da0fe43d83a Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Mon, 12 Mar 2018 21:42:05 +0800 Subject: [PATCH 04/29] Revert "none" This reverts commit f852a1ef0dbe94e61fefc0c1a3c4d3322e7d44c5. --- level1/p06_Goldbach/Goldbach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/level1/p06_Goldbach/Goldbach.c b/level1/p06_Goldbach/Goldbach.c index 2983a0a5..687d51c6 100644 --- a/level1/p06_Goldbach/Goldbach.c +++ b/level1/p06_Goldbach/Goldbach.c @@ -5,7 +5,7 @@ int primes(int *prime); void main() { - int n_prime = 26; //100鍐呮湁25涓川鏁板拰璇佹槑鎵闇鐢ㄥ埌鐨1 + int n_prime = 26; //100有25个质数和1 int prime[26]; primes(prime); for (int n = 3; n <= 100; n++) From 159452ff6327d87263764ffcd7752d9673baa3b6 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Mon, 12 Mar 2018 21:42:12 +0800 Subject: [PATCH 05/29] Revert "Revert "none"" This reverts commit a2d35904fc8e428a52b3539c1c944da0fe43d83a. --- level1/p06_Goldbach/Goldbach.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/level1/p06_Goldbach/Goldbach.c b/level1/p06_Goldbach/Goldbach.c index 687d51c6..2983a0a5 100644 --- a/level1/p06_Goldbach/Goldbach.c +++ b/level1/p06_Goldbach/Goldbach.c @@ -5,7 +5,7 @@ int primes(int *prime); void main() { - int n_prime = 26; //100有25个质数和1 + int n_prime = 26; //100鍐呮湁25涓川鏁板拰璇佹槑鎵闇鐢ㄥ埌鐨1 int prime[26]; primes(prime); for (int n = 3; n <= 100; n++) From 14960c644d3a038b30d25d24693b958c5b52a393 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Mon, 12 Mar 2018 21:48:22 +0800 Subject: [PATCH 06/29] none --- level1/p01_runningLetter/runningLetter.c | 35 ---------------- level1/p02_isPrime/isPrime.c | 25 ------------ level1/p03_Diophantus/Diophantus.c | 21 ---------- level1/p04_ narcissus/narcissus.c | 20 ---------- level1/p05_allPrimes/allPrimes.c | 21 ---------- level1/p06_Goldbach/Goldbach.c | 51 ------------------------ 6 files changed, 173 deletions(-) delete mode 100644 level1/p01_runningLetter/runningLetter.c delete mode 100644 level1/p02_isPrime/isPrime.c delete mode 100644 level1/p03_Diophantus/Diophantus.c delete mode 100644 level1/p04_ narcissus/narcissus.c delete mode 100644 level1/p05_allPrimes/allPrimes.c delete mode 100644 level1/p06_Goldbach/Goldbach.c diff --git a/level1/p01_runningLetter/runningLetter.c b/level1/p01_runningLetter/runningLetter.c deleted file mode 100644 index 219e6750..00000000 --- a/level1/p01_runningLetter/runningLetter.c +++ /dev/null @@ -1,35 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include -#include -#include -#define screen_l 50 - -int main() -{ - system("mode con cols=50 lines=20"); - int l_w; - char words[36]; - scanf("%s", &words); - l_w = strlen(words); - for (int space_l = 0; space_l <= screen_l - l_w; space_l++) - { - for (int n = 0; n < space_l; n++) - { - printf(" "); - } - printf("%s", words); - Sleep(100); - system("CLS"); - } - for (int space_l = screen_l - l_w; space_l > 0; space_l--) - { - for (int n = space_l; n > 0; n--) - { - printf(" "); - } - printf("%s", words); - Sleep(100); - system("CLS"); - } - return 0; -} \ No newline at end of file diff --git a/level1/p02_isPrime/isPrime.c b/level1/p02_isPrime/isPrime.c deleted file mode 100644 index b1b42719..00000000 --- a/level1/p02_isPrime/isPrime.c +++ /dev/null @@ -1,25 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include - -void main() -{ - long long int input_n; - scanf("%lld", &input_n); - if (input_n == 1) - { - printf("The number is not a Prime.\n"); - goto bottom; - } - for (int n = 2; n*n <= input_n; n++) - { - if (input_n%n == 0) - { - printf("The number is not a Prime.\n"); - goto bottom; - } - } - printf("The number is a Prime.\n"); -bottom: - getchar(); - getchar(); -} \ No newline at end of file diff --git a/level1/p03_Diophantus/Diophantus.c b/level1/p03_Diophantus/Diophantus.c deleted file mode 100644 index af088117..00000000 --- a/level1/p03_Diophantus/Diophantus.c +++ /dev/null @@ -1,21 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include - -void main() -{ - int d_age; - int s_age; - for (int n = 1; n < 1000; n++) - { - if (n % 12 == 0) - if (n % 7 == 0) - { - s_age = 5 + (n / 12) + (n / 7) + (n / 6); - d_age = s_age * 2; - break; - } - } - printf("Diophantus is %d years old.", d_age); - getchar(); - getchar(); -} \ No newline at end of file diff --git a/level1/p04_ narcissus/narcissus.c b/level1/p04_ narcissus/narcissus.c deleted file mode 100644 index 694785ec..00000000 --- a/level1/p04_ narcissus/narcissus.c +++ /dev/null @@ -1,20 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include - -int power(int num, int times); - -void main() -{ - int p1, p2, p3; - for (int n=100; n < 1000; n++) - { - p1 = n % 10; - p2 = (n % 100) / 10; - p3 = (n - p1 - p2) / 100; - if (n == p1 * p1*p1 + p2 * p2*p2 + p3 * p3*p3) - { - printf("%d\n", n); - } - } - getchar(); -} \ No newline at end of file diff --git a/level1/p05_allPrimes/allPrimes.c b/level1/p05_allPrimes/allPrimes.c deleted file mode 100644 index ad561189..00000000 --- a/level1/p05_allPrimes/allPrimes.c +++ /dev/null @@ -1,21 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include -#include -#include - -void main() -{ - printf("2\n3\n4\n"); - for (int i = 2; i <= 1000; i++) - { - for (int n = 2; n*n <= i; n++) - { - if (i%n == 0) - break; - else if ((n+1)*(n+1) > i) - printf("%d\n", i); - } - } - printf("total time is:%ld ms",clock()); - getchar(); -} \ No newline at end of file diff --git a/level1/p06_Goldbach/Goldbach.c b/level1/p06_Goldbach/Goldbach.c deleted file mode 100644 index 2983a0a5..00000000 --- a/level1/p06_Goldbach/Goldbach.c +++ /dev/null @@ -1,51 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include - -int primes(int *prime); - -void main() -{ - int n_prime = 26; //100鍐呮湁25涓川鏁板拰璇佹槑鎵闇鐢ㄥ埌鐨1 - int prime[26]; - primes(prime); - for (int n = 3; n <= 100; n++) - { - for (int n1 = 0; n1 < 26; n1++) - { - for (int n2 = 1; n2 < 26; n2++) - { - if (prime[n1] + prime[n2] == n) - { - printf("%d = %d + %d\n", n, prime[n1], prime[n2]); - } - else if (prime[n1] + prime[n2] > n) - { - break; - } - } - } - } - getchar(); -} - -int primes(int *prime) -{ - prime[0] = 1; - prime[1] = 2; - prime[2] = 3; - int n_p=3; - for (int ni = 2; ni <= 100; ni++) - { - for (int i = 2; i*i <= ni; i++) - { - if (ni%i == 0) - break; - else if ((i + 1)*(i + 1) > ni && (i + 1)*(i + 1) != ni) - { - prime[n_p] = ni; - n_p++; - break; - } - } - } -} \ No newline at end of file From 8274d96edc8fb433c52466ebd3d1dcb46cbf2371 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Mon, 12 Mar 2018 21:49:23 +0800 Subject: [PATCH 07/29] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BA=A4=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p01_runningLetter/runningLetter.c | 35 ++++++++++++++++ level1/p02_isPrime/isPrime.c | 25 ++++++++++++ level1/p03_Diophantus/Diophantus.c | 21 ++++++++++ level1/p04_ narcissus/narcissus.c | 20 ++++++++++ level1/p05_allPrimes/allPrimes.c | 21 ++++++++++ level1/p06_Goldbach/Goldbach.c | 51 ++++++++++++++++++++++++ 6 files changed, 173 insertions(+) create mode 100644 level1/p01_runningLetter/runningLetter.c create mode 100644 level1/p02_isPrime/isPrime.c create mode 100644 level1/p03_Diophantus/Diophantus.c create mode 100644 level1/p04_ narcissus/narcissus.c create mode 100644 level1/p05_allPrimes/allPrimes.c create mode 100644 level1/p06_Goldbach/Goldbach.c diff --git a/level1/p01_runningLetter/runningLetter.c b/level1/p01_runningLetter/runningLetter.c new file mode 100644 index 00000000..219e6750 --- /dev/null +++ b/level1/p01_runningLetter/runningLetter.c @@ -0,0 +1,35 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#define screen_l 50 + +int main() +{ + system("mode con cols=50 lines=20"); + int l_w; + char words[36]; + scanf("%s", &words); + l_w = strlen(words); + for (int space_l = 0; space_l <= screen_l - l_w; space_l++) + { + for (int n = 0; n < space_l; n++) + { + printf(" "); + } + printf("%s", words); + Sleep(100); + system("CLS"); + } + for (int space_l = screen_l - l_w; space_l > 0; space_l--) + { + for (int n = space_l; n > 0; n--) + { + printf(" "); + } + printf("%s", words); + Sleep(100); + system("CLS"); + } + return 0; +} \ No newline at end of file diff --git a/level1/p02_isPrime/isPrime.c b/level1/p02_isPrime/isPrime.c new file mode 100644 index 00000000..b1b42719 --- /dev/null +++ b/level1/p02_isPrime/isPrime.c @@ -0,0 +1,25 @@ +#define _CRT_SECURE_NO_WARNINGS +#include + +void main() +{ + long long int input_n; + scanf("%lld", &input_n); + if (input_n == 1) + { + printf("The number is not a Prime.\n"); + goto bottom; + } + for (int n = 2; n*n <= input_n; n++) + { + if (input_n%n == 0) + { + printf("The number is not a Prime.\n"); + goto bottom; + } + } + printf("The number is a Prime.\n"); +bottom: + getchar(); + getchar(); +} \ No newline at end of file diff --git a/level1/p03_Diophantus/Diophantus.c b/level1/p03_Diophantus/Diophantus.c new file mode 100644 index 00000000..af088117 --- /dev/null +++ b/level1/p03_Diophantus/Diophantus.c @@ -0,0 +1,21 @@ +#define _CRT_SECURE_NO_WARNINGS +#include + +void main() +{ + int d_age; + int s_age; + for (int n = 1; n < 1000; n++) + { + if (n % 12 == 0) + if (n % 7 == 0) + { + s_age = 5 + (n / 12) + (n / 7) + (n / 6); + d_age = s_age * 2; + break; + } + } + printf("Diophantus is %d years old.", d_age); + getchar(); + getchar(); +} \ No newline at end of file diff --git a/level1/p04_ narcissus/narcissus.c b/level1/p04_ narcissus/narcissus.c new file mode 100644 index 00000000..694785ec --- /dev/null +++ b/level1/p04_ narcissus/narcissus.c @@ -0,0 +1,20 @@ +#define _CRT_SECURE_NO_WARNINGS +#include + +int power(int num, int times); + +void main() +{ + int p1, p2, p3; + for (int n=100; n < 1000; n++) + { + p1 = n % 10; + p2 = (n % 100) / 10; + p3 = (n - p1 - p2) / 100; + if (n == p1 * p1*p1 + p2 * p2*p2 + p3 * p3*p3) + { + printf("%d\n", n); + } + } + getchar(); +} \ No newline at end of file diff --git a/level1/p05_allPrimes/allPrimes.c b/level1/p05_allPrimes/allPrimes.c new file mode 100644 index 00000000..ad561189 --- /dev/null +++ b/level1/p05_allPrimes/allPrimes.c @@ -0,0 +1,21 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include + +void main() +{ + printf("2\n3\n4\n"); + for (int i = 2; i <= 1000; i++) + { + for (int n = 2; n*n <= i; n++) + { + if (i%n == 0) + break; + else if ((n+1)*(n+1) > i) + printf("%d\n", i); + } + } + printf("total time is:%ld ms",clock()); + getchar(); +} \ No newline at end of file diff --git a/level1/p06_Goldbach/Goldbach.c b/level1/p06_Goldbach/Goldbach.c new file mode 100644 index 00000000..2983a0a5 --- /dev/null +++ b/level1/p06_Goldbach/Goldbach.c @@ -0,0 +1,51 @@ +#define _CRT_SECURE_NO_WARNINGS +#include + +int primes(int *prime); + +void main() +{ + int n_prime = 26; //100鍐呮湁25涓川鏁板拰璇佹槑鎵闇鐢ㄥ埌鐨1 + int prime[26]; + primes(prime); + for (int n = 3; n <= 100; n++) + { + for (int n1 = 0; n1 < 26; n1++) + { + for (int n2 = 1; n2 < 26; n2++) + { + if (prime[n1] + prime[n2] == n) + { + printf("%d = %d + %d\n", n, prime[n1], prime[n2]); + } + else if (prime[n1] + prime[n2] > n) + { + break; + } + } + } + } + getchar(); +} + +int primes(int *prime) +{ + prime[0] = 1; + prime[1] = 2; + prime[2] = 3; + int n_p=3; + for (int ni = 2; ni <= 100; ni++) + { + for (int i = 2; i*i <= ni; i++) + { + if (ni%i == 0) + break; + else if ((i + 1)*(i + 1) > ni && (i + 1)*(i + 1) != ni) + { + prime[n_p] = ni; + n_p++; + break; + } + } + } +} \ No newline at end of file From 70643c301396bbf7c77dab7b1919af9ea916c2be Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Tue, 13 Mar 2018 23:18:52 +0800 Subject: [PATCH 08/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E6=B1=89?= =?UTF-8?q?=E8=AF=BA=E5=A1=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p08_hanoi/hanoi.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 level1/p08_hanoi/hanoi.c diff --git a/level1/p08_hanoi/hanoi.c b/level1/p08_hanoi/hanoi.c new file mode 100644 index 00000000..1223ff18 --- /dev/null +++ b/level1/p08_hanoi/hanoi.c @@ -0,0 +1,27 @@ +#include +#define level_h 64 + +void move(int level, char A, char B, char C); + +void main() +{ + char A = 'A'; + char B = 'B'; + char C = 'C'; + move(level_h, A, B, C); + getchar(); +} + +void move(int level, char A, char B, char C) +{ + if (level == 1) + { + printf("%c --> %c\n", A, C); + } + else + { + move(level - 1, A, C, B); + printf("%c --> %c\n", A, C); + move(level - 1, B, A, C); + } +} \ No newline at end of file From 1431634545d77a798adc4cb7d889396a679bb93d Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Tue, 13 Mar 2018 23:24:36 +0800 Subject: [PATCH 09/29] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p01_runningLetter/runningLetter.c | 35 ---------------- level1/p02_isPrime/isPrime.c | 25 ------------ level1/p03_Diophantus/Diophantus.c | 21 ---------- level1/p04_ narcissus/narcissus.c | 20 ---------- level1/p05_allPrimes/allPrimes.c | 21 ---------- level1/p06_Goldbach/Goldbach.c | 51 ------------------------ level1/p08_hanoi/hanoi.c | 27 ------------- 7 files changed, 200 deletions(-) delete mode 100644 level1/p01_runningLetter/runningLetter.c delete mode 100644 level1/p02_isPrime/isPrime.c delete mode 100644 level1/p03_Diophantus/Diophantus.c delete mode 100644 level1/p04_ narcissus/narcissus.c delete mode 100644 level1/p05_allPrimes/allPrimes.c delete mode 100644 level1/p06_Goldbach/Goldbach.c delete mode 100644 level1/p08_hanoi/hanoi.c diff --git a/level1/p01_runningLetter/runningLetter.c b/level1/p01_runningLetter/runningLetter.c deleted file mode 100644 index 219e6750..00000000 --- a/level1/p01_runningLetter/runningLetter.c +++ /dev/null @@ -1,35 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include -#include -#include -#define screen_l 50 - -int main() -{ - system("mode con cols=50 lines=20"); - int l_w; - char words[36]; - scanf("%s", &words); - l_w = strlen(words); - for (int space_l = 0; space_l <= screen_l - l_w; space_l++) - { - for (int n = 0; n < space_l; n++) - { - printf(" "); - } - printf("%s", words); - Sleep(100); - system("CLS"); - } - for (int space_l = screen_l - l_w; space_l > 0; space_l--) - { - for (int n = space_l; n > 0; n--) - { - printf(" "); - } - printf("%s", words); - Sleep(100); - system("CLS"); - } - return 0; -} \ No newline at end of file diff --git a/level1/p02_isPrime/isPrime.c b/level1/p02_isPrime/isPrime.c deleted file mode 100644 index b1b42719..00000000 --- a/level1/p02_isPrime/isPrime.c +++ /dev/null @@ -1,25 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include - -void main() -{ - long long int input_n; - scanf("%lld", &input_n); - if (input_n == 1) - { - printf("The number is not a Prime.\n"); - goto bottom; - } - for (int n = 2; n*n <= input_n; n++) - { - if (input_n%n == 0) - { - printf("The number is not a Prime.\n"); - goto bottom; - } - } - printf("The number is a Prime.\n"); -bottom: - getchar(); - getchar(); -} \ No newline at end of file diff --git a/level1/p03_Diophantus/Diophantus.c b/level1/p03_Diophantus/Diophantus.c deleted file mode 100644 index af088117..00000000 --- a/level1/p03_Diophantus/Diophantus.c +++ /dev/null @@ -1,21 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include - -void main() -{ - int d_age; - int s_age; - for (int n = 1; n < 1000; n++) - { - if (n % 12 == 0) - if (n % 7 == 0) - { - s_age = 5 + (n / 12) + (n / 7) + (n / 6); - d_age = s_age * 2; - break; - } - } - printf("Diophantus is %d years old.", d_age); - getchar(); - getchar(); -} \ No newline at end of file diff --git a/level1/p04_ narcissus/narcissus.c b/level1/p04_ narcissus/narcissus.c deleted file mode 100644 index 694785ec..00000000 --- a/level1/p04_ narcissus/narcissus.c +++ /dev/null @@ -1,20 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include - -int power(int num, int times); - -void main() -{ - int p1, p2, p3; - for (int n=100; n < 1000; n++) - { - p1 = n % 10; - p2 = (n % 100) / 10; - p3 = (n - p1 - p2) / 100; - if (n == p1 * p1*p1 + p2 * p2*p2 + p3 * p3*p3) - { - printf("%d\n", n); - } - } - getchar(); -} \ No newline at end of file diff --git a/level1/p05_allPrimes/allPrimes.c b/level1/p05_allPrimes/allPrimes.c deleted file mode 100644 index ad561189..00000000 --- a/level1/p05_allPrimes/allPrimes.c +++ /dev/null @@ -1,21 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include -#include -#include - -void main() -{ - printf("2\n3\n4\n"); - for (int i = 2; i <= 1000; i++) - { - for (int n = 2; n*n <= i; n++) - { - if (i%n == 0) - break; - else if ((n+1)*(n+1) > i) - printf("%d\n", i); - } - } - printf("total time is:%ld ms",clock()); - getchar(); -} \ No newline at end of file diff --git a/level1/p06_Goldbach/Goldbach.c b/level1/p06_Goldbach/Goldbach.c deleted file mode 100644 index 2983a0a5..00000000 --- a/level1/p06_Goldbach/Goldbach.c +++ /dev/null @@ -1,51 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS -#include - -int primes(int *prime); - -void main() -{ - int n_prime = 26; //100鍐呮湁25涓川鏁板拰璇佹槑鎵闇鐢ㄥ埌鐨1 - int prime[26]; - primes(prime); - for (int n = 3; n <= 100; n++) - { - for (int n1 = 0; n1 < 26; n1++) - { - for (int n2 = 1; n2 < 26; n2++) - { - if (prime[n1] + prime[n2] == n) - { - printf("%d = %d + %d\n", n, prime[n1], prime[n2]); - } - else if (prime[n1] + prime[n2] > n) - { - break; - } - } - } - } - getchar(); -} - -int primes(int *prime) -{ - prime[0] = 1; - prime[1] = 2; - prime[2] = 3; - int n_p=3; - for (int ni = 2; ni <= 100; ni++) - { - for (int i = 2; i*i <= ni; i++) - { - if (ni%i == 0) - break; - else if ((i + 1)*(i + 1) > ni && (i + 1)*(i + 1) != ni) - { - prime[n_p] = ni; - n_p++; - break; - } - } - } -} \ No newline at end of file diff --git a/level1/p08_hanoi/hanoi.c b/level1/p08_hanoi/hanoi.c deleted file mode 100644 index 1223ff18..00000000 --- a/level1/p08_hanoi/hanoi.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#define level_h 64 - -void move(int level, char A, char B, char C); - -void main() -{ - char A = 'A'; - char B = 'B'; - char C = 'C'; - move(level_h, A, B, C); - getchar(); -} - -void move(int level, char A, char B, char C) -{ - if (level == 1) - { - printf("%c --> %c\n", A, C); - } - else - { - move(level - 1, A, C, B); - printf("%c --> %c\n", A, C); - move(level - 1, B, A, C); - } -} \ No newline at end of file From 201ccd6245ac05b4720b8f5530c87f59b7124d14 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Tue, 13 Mar 2018 23:25:16 +0800 Subject: [PATCH 10/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86runningLetter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p01_runningLetter/runningLetter.c | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 level1/p01_runningLetter/runningLetter.c diff --git a/level1/p01_runningLetter/runningLetter.c b/level1/p01_runningLetter/runningLetter.c new file mode 100644 index 00000000..219e6750 --- /dev/null +++ b/level1/p01_runningLetter/runningLetter.c @@ -0,0 +1,35 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#define screen_l 50 + +int main() +{ + system("mode con cols=50 lines=20"); + int l_w; + char words[36]; + scanf("%s", &words); + l_w = strlen(words); + for (int space_l = 0; space_l <= screen_l - l_w; space_l++) + { + for (int n = 0; n < space_l; n++) + { + printf(" "); + } + printf("%s", words); + Sleep(100); + system("CLS"); + } + for (int space_l = screen_l - l_w; space_l > 0; space_l--) + { + for (int n = space_l; n > 0; n--) + { + printf(" "); + } + printf("%s", words); + Sleep(100); + system("CLS"); + } + return 0; +} \ No newline at end of file From 975cd250e3b7479de4ca375d0bbbea67c4b6e95e Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Tue, 13 Mar 2018 23:25:29 +0800 Subject: [PATCH 11/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86isPrime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p02_isPrime/isPrime.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 level1/p02_isPrime/isPrime.c diff --git a/level1/p02_isPrime/isPrime.c b/level1/p02_isPrime/isPrime.c new file mode 100644 index 00000000..b1b42719 --- /dev/null +++ b/level1/p02_isPrime/isPrime.c @@ -0,0 +1,25 @@ +#define _CRT_SECURE_NO_WARNINGS +#include + +void main() +{ + long long int input_n; + scanf("%lld", &input_n); + if (input_n == 1) + { + printf("The number is not a Prime.\n"); + goto bottom; + } + for (int n = 2; n*n <= input_n; n++) + { + if (input_n%n == 0) + { + printf("The number is not a Prime.\n"); + goto bottom; + } + } + printf("The number is a Prime.\n"); +bottom: + getchar(); + getchar(); +} \ No newline at end of file From abbff724b060900b23a7cdb6c99255cadfce2396 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Tue, 13 Mar 2018 23:25:48 +0800 Subject: [PATCH 12/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86Diophantus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p03_Diophantus/Diophantus.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 level1/p03_Diophantus/Diophantus.c diff --git a/level1/p03_Diophantus/Diophantus.c b/level1/p03_Diophantus/Diophantus.c new file mode 100644 index 00000000..af088117 --- /dev/null +++ b/level1/p03_Diophantus/Diophantus.c @@ -0,0 +1,21 @@ +#define _CRT_SECURE_NO_WARNINGS +#include + +void main() +{ + int d_age; + int s_age; + for (int n = 1; n < 1000; n++) + { + if (n % 12 == 0) + if (n % 7 == 0) + { + s_age = 5 + (n / 12) + (n / 7) + (n / 6); + d_age = s_age * 2; + break; + } + } + printf("Diophantus is %d years old.", d_age); + getchar(); + getchar(); +} \ No newline at end of file From 531dffb544ad02b454c7844b79d3ca20609d6750 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Tue, 13 Mar 2018 23:26:04 +0800 Subject: [PATCH 13/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86narcissus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p04_ narcissus/narcissus.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 level1/p04_ narcissus/narcissus.c diff --git a/level1/p04_ narcissus/narcissus.c b/level1/p04_ narcissus/narcissus.c new file mode 100644 index 00000000..694785ec --- /dev/null +++ b/level1/p04_ narcissus/narcissus.c @@ -0,0 +1,20 @@ +#define _CRT_SECURE_NO_WARNINGS +#include + +int power(int num, int times); + +void main() +{ + int p1, p2, p3; + for (int n=100; n < 1000; n++) + { + p1 = n % 10; + p2 = (n % 100) / 10; + p3 = (n - p1 - p2) / 100; + if (n == p1 * p1*p1 + p2 * p2*p2 + p3 * p3*p3) + { + printf("%d\n", n); + } + } + getchar(); +} \ No newline at end of file From fa80d9b86b53cdfbda3ad7eb6d782f21cc385956 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Tue, 13 Mar 2018 23:26:20 +0800 Subject: [PATCH 14/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86allPrime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p05_allPrimes/allPrimes.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 level1/p05_allPrimes/allPrimes.c diff --git a/level1/p05_allPrimes/allPrimes.c b/level1/p05_allPrimes/allPrimes.c new file mode 100644 index 00000000..ad561189 --- /dev/null +++ b/level1/p05_allPrimes/allPrimes.c @@ -0,0 +1,21 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include + +void main() +{ + printf("2\n3\n4\n"); + for (int i = 2; i <= 1000; i++) + { + for (int n = 2; n*n <= i; n++) + { + if (i%n == 0) + break; + else if ((n+1)*(n+1) > i) + printf("%d\n", i); + } + } + printf("total time is:%ld ms",clock()); + getchar(); +} \ No newline at end of file From e72bdd9e068c8eb2fd360f89e9410a0ddfa98168 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Tue, 13 Mar 2018 23:26:35 +0800 Subject: [PATCH 15/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86Goldbach?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p06_Goldbach/Goldbach.c | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 level1/p06_Goldbach/Goldbach.c diff --git a/level1/p06_Goldbach/Goldbach.c b/level1/p06_Goldbach/Goldbach.c new file mode 100644 index 00000000..2983a0a5 --- /dev/null +++ b/level1/p06_Goldbach/Goldbach.c @@ -0,0 +1,51 @@ +#define _CRT_SECURE_NO_WARNINGS +#include + +int primes(int *prime); + +void main() +{ + int n_prime = 26; //100鍐呮湁25涓川鏁板拰璇佹槑鎵闇鐢ㄥ埌鐨1 + int prime[26]; + primes(prime); + for (int n = 3; n <= 100; n++) + { + for (int n1 = 0; n1 < 26; n1++) + { + for (int n2 = 1; n2 < 26; n2++) + { + if (prime[n1] + prime[n2] == n) + { + printf("%d = %d + %d\n", n, prime[n1], prime[n2]); + } + else if (prime[n1] + prime[n2] > n) + { + break; + } + } + } + } + getchar(); +} + +int primes(int *prime) +{ + prime[0] = 1; + prime[1] = 2; + prime[2] = 3; + int n_p=3; + for (int ni = 2; ni <= 100; ni++) + { + for (int i = 2; i*i <= ni; i++) + { + if (ni%i == 0) + break; + else if ((i + 1)*(i + 1) > ni && (i + 1)*(i + 1) != ni) + { + prime[n_p] = ni; + n_p++; + break; + } + } + } +} \ No newline at end of file From 42c4d150bb00577b3ac467d22d8403dbd2dfbf0e Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Tue, 13 Mar 2018 23:26:45 +0800 Subject: [PATCH 16/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86hanoi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p08_hanoi/hanoi.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 level1/p08_hanoi/hanoi.c diff --git a/level1/p08_hanoi/hanoi.c b/level1/p08_hanoi/hanoi.c new file mode 100644 index 00000000..1223ff18 --- /dev/null +++ b/level1/p08_hanoi/hanoi.c @@ -0,0 +1,27 @@ +#include +#define level_h 64 + +void move(int level, char A, char B, char C); + +void main() +{ + char A = 'A'; + char B = 'B'; + char C = 'C'; + move(level_h, A, B, C); + getchar(); +} + +void move(int level, char A, char B, char C) +{ + if (level == 1) + { + printf("%c --> %c\n", A, C); + } + else + { + move(level - 1, A, C, B); + printf("%c --> %c\n", A, C); + move(level - 1, B, A, C); + } +} \ No newline at end of file From a19ee7d3fc30e4e41d7427b84f5ee33f6108ce2a Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Wed, 14 Mar 2018 17:04:58 +0800 Subject: [PATCH 17/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86maze?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p09_maze/maze.c | 123 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 level1/p09_maze/maze.c diff --git a/level1/p09_maze/maze.c b/level1/p09_maze/maze.c new file mode 100644 index 00000000..bae7a678 --- /dev/null +++ b/level1/p09_maze/maze.c @@ -0,0 +1,123 @@ +锘#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#include + +void createmaze(int maze[][20]); +void draw(int maze[][20]); + +void main() +{ + system("mode con cols=50 lines=22"); +replay: + int dir = 0; + int maze[20][20]; + int posi[2] = {1,1}; + createmaze(maze); + maze[1][1] = 2; //2琛ㄧず鐜╁ + draw(maze); + while(maze[18][18] != 2) + { + dir = _getch(); + switch (dir) + { + case 72: //up + if (maze[posi[0] - 1][posi[1]] == 0 || maze[posi[0] - 1][posi[1]] == 3) + { + maze[posi[0]][posi[1]] = 0; + posi[0] = posi[0] - 1; + maze[posi[0]][posi[1]] = 2; + draw(maze); + } + break; + case 80: //down + if (maze[posi[0] + 1][posi[1]] == 0 || maze[posi[0] + 1][posi[1]] == 3) + { + maze[posi[0]][posi[1]] = 0; + posi[0] = posi[0] + 1; + maze[posi[0]][posi[1]] = 2; + draw(maze); + } + break; + case 75: //left + if (maze[posi[0]][posi[1] - 1] == 0 || maze[posi[0]][posi[1] - 1] == 3) + { + maze[posi[0]][posi[1]] = 0; + posi[1] = posi[1] - 1; + maze[posi[0]][posi[1]] = 2; + draw(maze); + } + break; + case 77: //right + if (maze[posi[0]][posi[1] + 1] == 0 || maze[posi[0]][posi[1] + 1] == 0) + { + maze[posi[0]][posi[1]] = 0; + posi[1] = posi[1] + 1; + maze[posi[0]][posi[1]] = 2; + draw(maze); + } + break; + case 'r': //recreate a maze + { + goto replay; + break; + } + default:; + } + } + +} + +void createmaze(int maze[][20]) +{ + for (int n1 = 1; n1 < 19; n1++) + { + for (int n2 = 1; n2 < 19; n2++) + { + if (rand() % 4 + 1 > 1) + { + maze[n1][n2] = 0; //0琛ㄧず绌 + } + else + { + maze[n1][n2] = 1; //1琛ㄧず澧 + } + } + } + for (int n = 0; n < 20; n++) + { + maze[0][n] = 1; + maze[19][n] = 1; + maze[n][0] = 1; + maze[n][19] = 1; //鐢熸垚杈圭晫澧 + } + maze[18][18] = 3; //缁堢偣 +} + +void draw(int maze[][20]) +{ + system("cls"); + for (int i = 0; i < 20; i++) + { + for (int j = 0; j < 20; j++) + { + switch (maze[i][j]) + { + case 0: + printf(" "); + break; + case 1: + printf("澧"); + break; + case 2: + printf("浣"); + break; + case 3: + printf("缁"); + break; + } + } + printf("\n"); + } +} \ No newline at end of file From 131f11fc02c2f783ff15308cc7c3f808e01e8e06 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Wed, 14 Mar 2018 21:32:35 +0800 Subject: [PATCH 18/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86encrypt=5Fdecr?= =?UTF-8?q?ypt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p07_encrypt_decrypt/encrypt_decrypt.c | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 level1/p07_encrypt_decrypt/encrypt_decrypt.c diff --git a/level1/p07_encrypt_decrypt/encrypt_decrypt.c b/level1/p07_encrypt_decrypt/encrypt_decrypt.c new file mode 100644 index 00000000..a51ed243 --- /dev/null +++ b/level1/p07_encrypt_decrypt/encrypt_decrypt.c @@ -0,0 +1,36 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include + +void encrypt(char *words_1, int n); +void decrypt(char *words_1, int n); + +void main() +{ + char words[10000]; + scanf("%s", &words); + int l_words = strlen(words); + encrypt(words, l_words); + printf("%s", words); + getchar(); + getchar(); + decrypt(words, l_words); + printf("%s", words); + getchar(); +} + +void encrypt(char *words_1, int n) +{ + for (int i = 0; i < n; i++) + { + words_1[i] = words_1[i] + 1; + } +} + +void decrypt(char *words_1, int n) +{ + for (int i = 0; i < n; i++) + { + words_1[i] = words_1[i] - 1; + } +} \ No newline at end of file From ac0192174bb4519c776f0ac570acc70c9591925e Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Fri, 16 Mar 2018 20:00:35 +0800 Subject: [PATCH 19/29] =?UTF-8?q?=E4=BF=AE=E6=94=B9runningLetter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p01_runningLetter/runningLetter.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/level1/p01_runningLetter/runningLetter.c b/level1/p01_runningLetter/runningLetter.c index 219e6750..d54c3eb0 100644 --- a/level1/p01_runningLetter/runningLetter.c +++ b/level1/p01_runningLetter/runningLetter.c @@ -2,18 +2,19 @@ #include #include #include -#define screen_l 50 +#define SCREEN_WID 50 +#define SLEEP_TIME 100 int main() { system("mode con cols=50 lines=20"); - int l_w; - char words[36]; + int length_word; + char words[50]; scanf("%s", &words); - l_w = strlen(words); - for (int space_l = 0; space_l <= screen_l - l_w; space_l++) + length_word = strlen(words); + for (int space_left = 0; space_left <= SCREEN_WID - length_word; space_left++) { - for (int n = 0; n < space_l; n++) + for (int n = 0; n < space_left; n++) { printf(" "); } @@ -21,14 +22,14 @@ int main() Sleep(100); system("CLS"); } - for (int space_l = screen_l - l_w; space_l > 0; space_l--) + for (int space_left = SCREEN_WID - length_word; space_left > 0; space_left--) { - for (int n = space_l; n > 0; n--) + for (int n = space_left; n > 0; n--) { printf(" "); } printf("%s", words); - Sleep(100); + Sleep(SLEEP_TIME); system("CLS"); } return 0; From d609bb34bebb3c4eca3dfd320d2c0d3b4f0d5c10 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Fri, 16 Mar 2018 20:02:21 +0800 Subject: [PATCH 20/29] =?UTF-8?q?=E4=BF=AE=E6=94=B9isPrime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p02_isPrime/isPrime.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/level1/p02_isPrime/isPrime.c b/level1/p02_isPrime/isPrime.c index b1b42719..71a7cfde 100644 --- a/level1/p02_isPrime/isPrime.c +++ b/level1/p02_isPrime/isPrime.c @@ -3,7 +3,7 @@ void main() { - long long int input_n; + int input_n; scanf("%lld", &input_n); if (input_n == 1) { @@ -15,11 +15,10 @@ void main() if (input_n%n == 0) { printf("The number is not a Prime.\n"); - goto bottom; + break锛 } + printf("The number is a Prime.\n"); } - printf("The number is a Prime.\n"); -bottom: getchar(); getchar(); } \ No newline at end of file From bc5eddd840678df69927f1eb06770cf7da54c76a Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Fri, 16 Mar 2018 20:03:19 +0800 Subject: [PATCH 21/29] =?UTF-8?q?=E4=BF=AE=E6=94=B9allPrime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p05_allPrimes/allPrimes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/level1/p05_allPrimes/allPrimes.c b/level1/p05_allPrimes/allPrimes.c index ad561189..06bcd8de 100644 --- a/level1/p05_allPrimes/allPrimes.c +++ b/level1/p05_allPrimes/allPrimes.c @@ -12,7 +12,7 @@ void main() { if (i%n == 0) break; - else if ((n+1)*(n+1) > i) + if ((n+1)*(n+1) > i) printf("%d\n", i); } } From 61e0f00a9f3d42eff873daabd186c92b9ec2a22b Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Fri, 16 Mar 2018 20:04:24 +0800 Subject: [PATCH 22/29] =?UTF-8?q?=E4=BF=AE=E6=94=B9Goldbach?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p06_Goldbach/Goldbach.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/level1/p06_Goldbach/Goldbach.c b/level1/p06_Goldbach/Goldbach.c index 2983a0a5..163a1f98 100644 --- a/level1/p06_Goldbach/Goldbach.c +++ b/level1/p06_Goldbach/Goldbach.c @@ -1,13 +1,13 @@ #define _CRT_SECURE_NO_WARNINGS #include -int primes(int *prime); +int make_primes(int *prime); void main() { int n_prime = 26; //100鍐呮湁25涓川鏁板拰璇佹槑鎵闇鐢ㄥ埌鐨1 int prime[26]; - primes(prime); + make_primes(prime); for (int n = 3; n <= 100; n++) { for (int n1 = 0; n1 < 26; n1++) @@ -28,7 +28,7 @@ void main() getchar(); } -int primes(int *prime) +int make_primes(int *prime) { prime[0] = 1; prime[1] = 2; From 02d6ab10f89bd57c6259e612860bd190a66d4914 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Fri, 16 Mar 2018 20:05:32 +0800 Subject: [PATCH 23/29] =?UTF-8?q?=E4=BF=AE=E6=94=B9Goldbach?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p06_Goldbach/Goldbach.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/level1/p06_Goldbach/Goldbach.c b/level1/p06_Goldbach/Goldbach.c index 163a1f98..58cd3a78 100644 --- a/level1/p06_Goldbach/Goldbach.c +++ b/level1/p06_Goldbach/Goldbach.c @@ -34,15 +34,15 @@ int make_primes(int *prime) prime[1] = 2; prime[2] = 3; int n_p=3; - for (int ni = 2; ni <= 100; ni++) + for (int i = 2; i <= 100; i++) { - for (int i = 2; i*i <= ni; i++) + for (int j = 2; j*j <= i; j++) { - if (ni%i == 0) + if (i%j == 0) break; - else if ((i + 1)*(i + 1) > ni && (i + 1)*(i + 1) != ni) + else if ((j + 1)*(j + 1) > i && (j + 1)*(j + 1) != i) { - prime[n_p] = ni; + prime[n_p] = i; n_p++; break; } From def291a7d7112145cb9d55263a664596739ea4e3 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Fri, 16 Mar 2018 20:08:04 +0800 Subject: [PATCH 24/29] =?UTF-8?q?=E4=BF=AE=E6=94=B9Hanoi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p08_hanoi/hanoi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/level1/p08_hanoi/hanoi.c b/level1/p08_hanoi/hanoi.c index 1223ff18..fc64755c 100644 --- a/level1/p08_hanoi/hanoi.c +++ b/level1/p08_hanoi/hanoi.c @@ -1,5 +1,5 @@ #include -#define level_h 64 +#define LEVEL_HANOI 64 void move(int level, char A, char B, char C); @@ -8,7 +8,7 @@ void main() char A = 'A'; char B = 'B'; char C = 'C'; - move(level_h, A, B, C); + move(LEVEL_HANOI, A, B, C); getchar(); } From 7007aacebc7d5e7326afbf09dc3e17f30782590f Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Sun, 18 Mar 2018 20:14:30 +0800 Subject: [PATCH 25/29] =?UTF-8?q?=E4=BF=AE=E6=94=B9maze?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p09_maze/maze.c | 62 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/level1/p09_maze/maze.c b/level1/p09_maze/maze.c index bae7a678..e0d7b015 100644 --- a/level1/p09_maze/maze.c +++ b/level1/p09_maze/maze.c @@ -4,57 +4,59 @@ #include #include -void createmaze(int maze[][20]); +void create_maze(int maze[][20]); void draw(int maze[][20]); +enum symbol{ empty, wall, player, terminal }; void main() { system("mode con cols=50 lines=22"); -replay: - int dir = 0; + int dir; int maze[20][20]; int posi[2] = {1,1}; - createmaze(maze); - maze[1][1] = 2; //2琛ㄧず鐜╁ +replay: + dir = 0; + create_maze(maze); + maze[1][1] = player; draw(maze); - while(maze[18][18] != 2) + while(maze[18][18] != player) { dir = _getch(); switch (dir) { case 72: //up - if (maze[posi[0] - 1][posi[1]] == 0 || maze[posi[0] - 1][posi[1]] == 3) + if (maze[posi[0] - 1][posi[1]] == empty || maze[posi[0] - 1][posi[1]] == terminal) { - maze[posi[0]][posi[1]] = 0; + maze[posi[0]][posi[1]] = empty; posi[0] = posi[0] - 1; - maze[posi[0]][posi[1]] = 2; + maze[posi[0]][posi[1]] = player; draw(maze); } break; case 80: //down - if (maze[posi[0] + 1][posi[1]] == 0 || maze[posi[0] + 1][posi[1]] == 3) + if (maze[posi[0] + 1][posi[1]] == empty || maze[posi[0] + 1][posi[1]] == terminal) { - maze[posi[0]][posi[1]] = 0; + maze[posi[0]][posi[1]] = empty; posi[0] = posi[0] + 1; - maze[posi[0]][posi[1]] = 2; + maze[posi[0]][posi[1]] = player; draw(maze); } break; case 75: //left - if (maze[posi[0]][posi[1] - 1] == 0 || maze[posi[0]][posi[1] - 1] == 3) + if (maze[posi[0]][posi[1] - 1] == empty || maze[posi[0]][posi[1] - 1] == terminal) { - maze[posi[0]][posi[1]] = 0; + maze[posi[0]][posi[1]] = empty; posi[1] = posi[1] - 1; - maze[posi[0]][posi[1]] = 2; + maze[posi[0]][posi[1]] = player; draw(maze); } break; case 77: //right - if (maze[posi[0]][posi[1] + 1] == 0 || maze[posi[0]][posi[1] + 1] == 0) + if (maze[posi[0]][posi[1] + 1] == empty || maze[posi[0]][posi[1] + 1] == terminal) { - maze[posi[0]][posi[1]] = 0; + maze[posi[0]][posi[1]] = empty; posi[1] = posi[1] + 1; - maze[posi[0]][posi[1]] = 2; + maze[posi[0]][posi[1]] = player; draw(maze); } break; @@ -69,7 +71,7 @@ void main() } -void createmaze(int maze[][20]) +void create_maze(int maze[][20]) { for (int n1 = 1; n1 < 19; n1++) { @@ -77,22 +79,22 @@ void createmaze(int maze[][20]) { if (rand() % 4 + 1 > 1) { - maze[n1][n2] = 0; //0琛ㄧず绌 + maze[n1][n2] = empty; } else { - maze[n1][n2] = 1; //1琛ㄧず澧 + maze[n1][n2] = wall; } } } for (int n = 0; n < 20; n++) { - maze[0][n] = 1; - maze[19][n] = 1; - maze[n][0] = 1; - maze[n][19] = 1; //鐢熸垚杈圭晫澧 + maze[0][n] = wall; + maze[19][n] = wall; + maze[n][0] = wall; + maze[n][19] = wall; } - maze[18][18] = 3; //缁堢偣 + maze[18][18] = terminal; } void draw(int maze[][20]) @@ -104,16 +106,16 @@ void draw(int maze[][20]) { switch (maze[i][j]) { - case 0: + case empty: printf(" "); break; - case 1: + case wall: printf("澧"); break; - case 2: + case player: printf("浣"); break; - case 3: + case terminal: printf("缁"); break; } From b28cd3cb01ea565b9152c3286aaef09a6725fdc4 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Tue, 20 Mar 2018 16:43:28 +0800 Subject: [PATCH 26/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86pushBoxes(?= =?UTF-8?q?=E5=8F=AA=E5=81=9A=E4=BA=86=E4=B8=80=E5=85=B3=E7=9A=84=E5=9C=B0?= =?UTF-8?q?=E5=9B=BE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p10_pushBoxes/level1.txt | 15 +++ level1/p10_pushBoxes/pushBoxes.c | 216 +++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+) create mode 100644 level1/p10_pushBoxes/level1.txt create mode 100644 level1/p10_pushBoxes/pushBoxes.c diff --git a/level1/p10_pushBoxes/level1.txt b/level1/p10_pushBoxes/level1.txt new file mode 100644 index 00000000..1ec21240 --- /dev/null +++ b/level1/p10_pushBoxes/level1.txt @@ -0,0 +1,15 @@ +111111111111111 +120100000000001 +100100111100001 +100004000100001 +100000000101401 +111111100101001 +100000000101001 +100100001100001 +104100000000001 +100111001111001 +100100000000001 +111111111100001 +100000000000001 +133300000000001 +111111111111111 \ No newline at end of file diff --git a/level1/p10_pushBoxes/pushBoxes.c b/level1/p10_pushBoxes/pushBoxes.c new file mode 100644 index 00000000..db4172eb --- /dev/null +++ b/level1/p10_pushBoxes/pushBoxes.c @@ -0,0 +1,216 @@ +锘#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#include +#define map_size 15 + +int set_level(int set_level, int map[][15], FILE *level); +void draw(int map[][15],int steps); +void refill_terminal(int map[][15]); +enum symbol { empty, wall, player, terminal ,box}; + +void main() +{ + system("mode con cols=60 lines=22"); + FILE *level; + int select_level; + int step_count = 0; + int dir = 0; + int map[15][15]; + int posi[2] = {1,1}; +re_select: + printf("please input a number between 1-3 to select levels.\n"); + scanf("%d", &select_level); + if (set_level(select_level, map, &level)) + { + goto re_select; + } + draw(map,step_count); + while (map[13][1] != box || map[13][2] != box || map[13][3] != box) + { + dir = _getch(); + switch (dir) + { + case 72: //up + step_count++; + if (map[posi[0] - 1][posi[1]] == empty || map[posi[0] - 1][posi[1]] == terminal) + { + map[posi[0]][posi[1]] = empty; + posi[0] = posi[0] - 1; + map[posi[0]][posi[1]] = player; + } + else if (map[posi[0] - 1][posi[1]] == box && (map[posi[0] - 2][posi[1]] == empty || map[posi[0] - 2][posi[1]] == terminal)) + { + map[posi[0]][posi[1]] = empty; + map[posi[0] - 1][posi[1]] = player; + posi[0] = posi[0] - 1; + map[posi[0] - 1][posi[1]] = box; + } + refill_terminal(map); + draw(map, step_count); + break; + case 80: //down + step_count++; + if (map[posi[0] + 1][posi[1]] == empty || map[posi[0] + 1][posi[1]] == terminal) + { + map[posi[0]][posi[1]] = empty; + posi[0] = posi[0] + 1; + map[posi[0]][posi[1]] = player; + } + else if (map[posi[0] + 1][posi[1]] == box && (map[posi[0] + 2][posi[1]] == empty || map[posi[0] + 2][posi[1]] == terminal)) + { + map[posi[0]][posi[1]] = empty; + map[posi[0] + 1][posi[1]] = player; + posi[0] = posi[0] + 1; + map[posi[0] + 1][posi[1]] = box; + } + refill_terminal(map); + draw(map, step_count); + break; + case 75: //left + step_count++; + if (map[posi[0]][posi[1] - 1] == empty || map[posi[0]][posi[1] - 1] == terminal) + { + map[posi[0]][posi[1]] = empty; + posi[1] = posi[1] - 1; + map[posi[0]][posi[1]] = player; + } + else if (map[posi[0]][posi[1] - 1] == box && (map[posi[0]][posi[1] - 2] == empty || map[posi[0]][posi[1] - 2] == terminal)) + { + map[posi[0]][posi[1]] = empty; + map[posi[0]][posi[1] - 1] = player; + posi[1] = posi[1] - 1; + map[posi[0]][posi[1] - 1] = box; + } + refill_terminal(map); + draw(map, step_count); + break; + case 77: //right + step_count++; + if (map[posi[0]][posi[1] + 1] == empty || map[posi[0]][posi[1] + 1] == terminal) + { + map[posi[0]][posi[1]] = empty; + posi[1] = posi[1] + 1; + map[posi[0]][posi[1]] = player; + } + else if (map[posi[0]][posi[1] + 1] == box && (map[posi[0]][posi[1] + 2] == empty || map[posi[0]][posi[1] + 2] == terminal)) + { + map[posi[0]][posi[1]] = empty; + map[posi[0]][posi[1] + 1] = player; + posi[1] = posi[1] + 1; + map[posi[0]][posi[1] + 1] = box; + } + refill_terminal(map); + draw(map, step_count); + break; + } + } + system("cls"); + printf("666 浣犺耽浜 666\n"); + system("pause"); +} + +int set_level(int set_level, int map[][15],FILE *level) +{ + char ch = '0'; + int num_n; + int n1 = 0; + int n2 = 0; + switch (set_level) + { + case 1: + level = fopen("level1.txt", "r"); + break; + case 2: + level = fopen("level2.txt", "r"); + break; + case 3: + level = fopen("level3.txt", "r"); + break; + } + if (level == NULL) + { + printf("can not find the map file.\nplease try another level.\n"); + return 1; + } + while (ch != EOF) + { + ch = fgetc(level); + switch (ch) + { + case '0': + num_n = 0; + break; + case '1': + num_n = 1; + break; + case '2': + num_n = 2; + break; + case'3': + num_n = 3; + break; + case '4': + num_n = 4; + break; + default: + break; + } + if (ch != '\n') + { + map[n1][n2] = num_n; + n2++; + } + else + { + n1++; + n2 = 0; + } + } + fclose(level); + return 0; +} + +void draw(int map[][15],int steps) +{ + system("cls"); + for (int i = 0; i < 15; i++) + { + for (int j = 0; j < 15; j++) + { + switch (map[i][j]) + { + case empty: + printf(" "); + break; + case wall: + printf("澧"); + break; + case player: + printf("浣"); + break; + case terminal: + printf("缁"); + break; + case box: + printf("绠"); + break; + } + } + printf("\n"); + } + printf("鎮ㄥ凡绉诲姩%d姝ャ俓n", steps); +} + +void refill_terminal(int map[][15]) +{ + for (int i = 1; i <= 3; i++) + { + if (map[13][i] != box && map[13][i] != player) + { + map[13][i] = terminal; + } + } + +} \ No newline at end of file From 2b5e7958b4c806c1118fbf10685616fb0154239f Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Thu, 29 Mar 2018 09:15:02 +0800 Subject: [PATCH 27/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86warehouse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p12_warehouse/goods_list.dat | Bin 0 -> 160 bytes level1/p12_warehouse/warehouse.c | 179 ++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 level1/p12_warehouse/goods_list.dat create mode 100644 level1/p12_warehouse/warehouse.c diff --git a/level1/p12_warehouse/goods_list.dat b/level1/p12_warehouse/goods_list.dat new file mode 100644 index 0000000000000000000000000000000000000000..1b5f1efdc6b906a9bf168e34e721e33fafcd2606 GIT binary patch literal 160 zcmb)R_fh literal 0 HcmV?d00001 diff --git a/level1/p12_warehouse/warehouse.c b/level1/p12_warehouse/warehouse.c new file mode 100644 index 00000000..98db130d --- /dev/null +++ b/level1/p12_warehouse/warehouse.c @@ -0,0 +1,179 @@ +锘#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include + +_Bool select_mode(void); +_Bool show_list(void); +_Bool storage(void); +_Bool outbound(void); + +struct goods { + int id; + char name[30]; + int number; +}good; +_Bool error = 0; + +int main() +{ + system("mode con cols=50 lines=20"); + select_mode(); +} + +_Bool select_mode(void) +{ + int mode; +re_input: + system("cls"); + for (int i = 0; i < 50; i++) + { + printf("*"); + } + for (int i = 0; i < 21; i++) + { + printf(" "); + } + printf("閫夋嫨妯″紡\n"); + + for (int i = 0; i < 50; i++) + { + printf("*"); + } + printf("\n1.鏄剧ず瀛樿揣鍒楄〃.\n"); + printf("2.鍏ュ簱\n"); + printf("3.鍑哄簱\n"); + printf("4.閫鍑虹▼搴"); + scanf("%d",&mode); + switch (mode) + { + case 1: + show_list(); + system("pause"); + break; + case 2: + storage(); + break; + case 3: + outbound(); + break; + case 4: + return 1; + default: + printf("閿欒鐨勮緭鍏n璇峰皾璇曟纭殑杈撳叆\n"); + system("pause"); + } + goto re_input; +} + +_Bool show_list(void) +{ + system("cls"); + FILE *list; + list = fopen("goods_list.dat", "rb"); + if (list == NULL) + { + return 1; + } + printf("\tID"); + printf("\t鍚嶇О"); + printf("\t鏁伴噺\n"); + while (fread(&good, sizeof(struct goods), 1, list) != 0) + { + printf("\t%d", good.id); + printf("\t%s", good.name); + printf("\t%d\n", good.number); + } + fclose(list); + return 0; +} + +_Bool storage(void) +{ + int id; + char mode; + FILE *list; +input_more: + system("cls"); + show_list(); + printf("1.鍚戝瓨璐у垪琛ㄤ腑娣诲姞鏂扮殑璐х墿銆俓n"); + printf("2.娣诲姞瀛樿揣鏁伴噺.\n"); + printf("鎸塺杩斿洖涓婄骇鑿滃崟.\n"); + good.id = 0; + scanf("%c",&mode); + switch (mode) + { + case '1': + printf("璇疯緭鍏ヨ揣鐗﹊d:\n"); + scanf("%d", &good.id); + printf("璇疯緭鍏ヨ揣鐗╁悕绉:\n"); + scanf("%s", &good.name); + printf("璇疯緭鍏ヨ揣鐗╂暟閲:\n"); + scanf("%d", &good.number); + list = fopen("goods_list.dat", "rb+"); + if (list == NULL) + { + return 1; + } + fseek(list,0,2); + fwrite(&good, sizeof(struct goods), 1, list); + fclose(list); + break; + case '2': + printf("璇疯緭鍏ヨ揣鐗﹊d浠ュ鍔犺揣鐗╂暟閲:\n"); + scanf("%d", &id); + list = fopen("goods_list.dat", "rb+"); + while(fread(&good, sizeof(struct goods), 1, list) != 0) + { + if (good.id = id) + { + int add_num=0; + printf("\t%d\t%s\t%d\n",good.id, good.name, good.number); + printf("璇疯緭鍏ュ閲:\n"); + scanf("%d", &add_num); + good.number += add_num; + fseek(list, -(int)sizeof(struct goods), 1); + fwrite(&good, sizeof(struct goods), 1, list); + fclose(list); + break; + } + } + break; + case 'r': + return 0; + } + goto input_more; +} +_Bool outbound(void) +{ + system("cls"); + int id; + FILE *list; +input_more: + good.id = 0; + list = fopen("goods_list.dat", "rb+"); + if (list == NULL) + { + return 1; + } + show_list(); + printf("鎸塺杩斿洖涓婄骇鑿滃崟.\n"); + printf("璇疯緭鍏ュ瓨璐d:\n"); + scanf("%d", &id); + while(fread(&good, sizeof(struct goods), 1, list) != 0) + { + if (good.id == id) + { + int jian_num = 0; + printf("\t%d\t%s\t%d\n", good.id, good.name, good.number); + printf("璇疯緭鍏ュ噺灏戦噺:\n"); + scanf("%d", &jian_num); + good.number -= jian_num; + fseek(list, -(int)sizeof(struct goods), 1); + fwrite(&good, sizeof(struct goods), 1, list); + fclose(list); + break; + } + } + goto input_more; +} \ No newline at end of file From 5c0fe9b75fd7069f52a993598991105029822f9a Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Thu, 29 Mar 2018 09:31:36 +0800 Subject: [PATCH 28/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86warehouse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p12_warehouse/warehouse.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/level1/p12_warehouse/warehouse.c b/level1/p12_warehouse/warehouse.c index 98db130d..89b6d697 100644 --- a/level1/p12_warehouse/warehouse.c +++ b/level1/p12_warehouse/warehouse.c @@ -148,6 +148,7 @@ _Bool outbound(void) { system("cls"); int id; + char mode; FILE *list; input_more: good.id = 0; @@ -158,8 +159,13 @@ _Bool outbound(void) } show_list(); printf("鎸塺杩斿洖涓婄骇鑿滃崟.\n"); - printf("璇疯緭鍏ュ瓨璐d:\n"); - scanf("%d", &id); + printf("鎴栬緭鍏ュ瓨璐d:\n"); + scanf("%c",&mode); + if (mode == 'r') + { + return 0; + } + scanf("%d",&id); while(fread(&good, sizeof(struct goods), 1, list) != 0) { if (good.id == id) From 1a5b046554cc837c5971551c035faf94e6eff668 Mon Sep 17 00:00:00 2001 From: Chen <34164851+MrNobodyBee@users.noreply.github.com> Date: Tue, 10 Apr 2018 09:47:32 +0800 Subject: [PATCH 29/29] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86linkedList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- level1/p11_linkedList/linkedList.c | 62 ++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 level1/p11_linkedList/linkedList.c diff --git a/level1/p11_linkedList/linkedList.c b/level1/p11_linkedList/linkedList.c new file mode 100644 index 00000000..be0f65fa --- /dev/null +++ b/level1/p11_linkedList/linkedList.c @@ -0,0 +1,62 @@ +锘#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +#define N_NODE 100 //鍋囪鏈100涓粨鐐 +#define MAX_VALUE 10 //閾捐〃涓璿alue鐨勬渶澶у +#define MIN_VALUE 0 //閾捐〃涓璿alue鐨勬渶灏忓 + +int main() +{ + int n = N_NODE; + int found = 0; + struct node { + int value; + struct node *next; + } *head, *node_a, *node_b,*inverse, *node_c; + head = node_a = (struct node *)malloc(sizeof(struct node)); + node_a->value = rand() % ((MAX_VALUE - MIN_VALUE)) + MIN_VALUE; + for (int i = 0; i < N_NODE; i++) + { + node_b = (struct node *)malloc(sizeof(struct node)); + node_a -> next = node_b; + node_a = node_b; + node_a->value = rand() % ((MAX_VALUE - MIN_VALUE)) + MIN_VALUE; + } + node_a->next = NULL; + inverse = node_a; + node_b = inverse; + for (int i = 0; i < N_NODE; i++,--n) + { + node_a = head; + for (int j = 0; j < n; j++) + { + node_a = node_a->next; + } + if (i != 0) + { + node_b->next = node_a; + node_b = node_a; + } + } + node_b->next = NULL; + node_a = inverse; + printf("搴忓彿浠0寮濮嬭绠梊n"); + for (int i = 0; i < N_NODE; i++) + { + if (i != 0) + { + node_a = node_a->next; + } + if (node_a->value == 5) + { + printf("搴忓彿涓:%d\n", i); + found = 1; + } + } + if (found == 0) + { + printf("-1"); + } + system("pause"); +} \ No newline at end of file