diff --git a/2020-Autumn/Backend/task_02/chenxiangwang0457/README.md b/2020-Autumn/Backend/task_02/chenxiangwang0457/README.md new file mode 100644 index 00000000..1edcaf6f --- /dev/null +++ b/2020-Autumn/Backend/task_02/chenxiangwang0457/README.md @@ -0,0 +1,6 @@ +**这次任务,我学习了动态数组的创建使用,学习了用指针来访问数组;** + + + + +*创建完动态数组,千万不要忘记free* diff --git "a/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\344\270\200\351\242\230.cpp" "b/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\344\270\200\351\242\230.cpp" new file mode 100644 index 00000000..a6c575b1 --- /dev/null +++ "b/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\344\270\200\351\242\230.cpp" @@ -0,0 +1,35 @@ +#include +#include +void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n) +{ + int i, j = 0; + for (i = m; i < m + n; i++) + { + nums1[i] = nums2[j]; + j++;//i=m+nʱ,ֵֹͣ; + }//ϲ; + for (i = 0; i < m + n - 1; i++) + { + for (j = 0; j < m + n - 1 - i; j++) + { + int temp; + if (nums1[j] > nums1[j + 1]) + { + temp = nums1[j]; + nums1[j] = nums1[j + 1]; + nums1[j + 1] = temp; + } + } + }//ð; +} +void main() { + int arr1[] = { 1,2,3,0,0,0 }, i; + int arr2[] = { 4,6,7 }; + merge(arr1, 3, 3, arr2, 3, 3);//ַ,ģ; + for (i = 0; i < 6; i++) + { + printf("%d ", arr1[i]); + } +} + + diff --git "a/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\344\270\211\351\242\230.cpp" "b/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\344\270\211\351\242\230.cpp" new file mode 100644 index 00000000..c019e4e2 --- /dev/null +++ "b/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\344\270\211\351\242\230.cpp" @@ -0,0 +1,14 @@ +#include +#include +void travelsall(int* a, int n) { + int i; + for (i = 0; i <= n - 1; i++) + { + printf("%d ", *(a + i)); + } +} +void main() { + int s[8] = { 1,2,3,4,5,6,7,8 }; + travelsall(s, 8); +} + diff --git "a/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\344\272\214\351\242\230.cpp" "b/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\344\272\214\351\242\230.cpp" new file mode 100644 index 00000000..c47849fa --- /dev/null +++ "b/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\344\272\214\351\242\230.cpp" @@ -0,0 +1,66 @@ +#include +#include +#include +void rotate(int** matrix, int matrixSize, int* matrixColSize) +{ + int i, j; + for (i = 0; i < matrixSize; i++) + { + for (j = i + 1; j < matrixSize; j++) + { + int temp; + temp = matrix[i][j]; + matrix[i][j] = matrix[j][i]; + matrix[j][i] = temp; + } + } + for (i = 0; i < matrixSize; i++) + { + for (j = 0; j < matrixSize / 2; j++) + { + int temp; + temp = matrix[i][j]; + matrix[i][j] = matrix[i][matrixSize - 1 - j]; + matrix[i][matrixSize - 1 - j] = temp; + } + } + return; +} +int main() { + int** arr; + int i, j, t = 3; + int* colmat = (int*)malloc(t * sizeof(int)); + arr = (int**)malloc(t * sizeof(int)); + for (i = 0; i < t; i++) + { + *(arr + i) = (int*)malloc(t * sizeof(int)); + } + printf("\n"); + for (i = 0; i < 3; i++) + { + for (j = 0; j < 3; j++) + { + scanf("%d", &arr[i][j]); + } + } + rotate(arr, 3, colmat); + for (i = 0; i < 3; i++) + { + for (j = 0; j < 3; j++) + { + printf("%d,\t", arr[i][j]); + } + printf("\n"); + } + for (i = 0; i < t; i++) + { + free(arr[i]); + } + free(arr); + free(colmat); + return 0; + +} + + + diff --git "a/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\344\272\224\351\242\230.cpp" "b/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\344\272\224\351\242\230.cpp" new file mode 100644 index 00000000..e76bdda0 --- /dev/null +++ "b/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\344\272\224\351\242\230.cpp" @@ -0,0 +1,35 @@ + +#include +#include +#include +int** creatArray(int m, int n) +{ + int i, j; + int** array, ** pt; + array = (int**)malloc(m * sizeof(int)); + for (i = 0; i < m; i++) + { + array[i] = (int*)malloc(n * sizeof(int)); + } + for (i = 0; i < m; i++) + { + for (j = 0; j < n; j++) + { + array[i][j]=i*n+j+1; + } + } + pt = array; + return pt; +} +void main() { + int** p, i, j; + p = creatArray(3, 3); + for (i = 0; i < 3; i++) + { + for (j = 0; j < 3; j++) + { + printf("%d ", *(*(p + i) + j)); + } + printf("\n"); + } +} diff --git "a/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\345\233\233\351\242\230.cpp" "b/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\345\233\233\351\242\230.cpp" new file mode 100644 index 00000000..b307b613 --- /dev/null +++ "b/2020-Autumn/Backend/task_02/chenxiangwang0457/\347\254\254\345\233\233\351\242\230.cpp" @@ -0,0 +1,28 @@ +#include +#include +#include +int* creatArray(int n) +{ + int* array, i, * pt; + array = (int*)malloc(n * sizeof(int)); + for (i = 0; i < n; i++) + { + array[i] = i + 1; + } + pt = array; + return pt; + +} +void main() { + int* p, i; + p = creatArray(8); + for (i = 0; i < 8; i++) + { + printf("%d ", *(p + i)); + } + +} + + + + diff --git a/2020-Autumn/Backend/task_03/chenxiangwang0457/RADEME.md b/2020-Autumn/Backend/task_03/chenxiangwang0457/RADEME.md new file mode 100644 index 00000000..e00f3945 --- /dev/null +++ b/2020-Autumn/Backend/task_03/chenxiangwang0457/RADEME.md @@ -0,0 +1 @@ +*之后会对关键代码处作出注释;做题过程中容易忽略局部变量在循环中的位置,之后会仔细思考;注意函数名称* diff --git "a/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\344\270\200\351\242\230.c" "b/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\344\270\200\351\242\230.c" new file mode 100644 index 00000000..1baee0a8 --- /dev/null +++ "b/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\344\270\200\351\242\230.c" @@ -0,0 +1,33 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +int findNumberInArray(int* arr, int length, int target) +{ + int count = 0; + int i; + for (i = 0; *(arr + i) != '\0'; i++) + { + if (*(arr + i) == target) + { + count = count + 1; + } + } + return count; +} +int main() +{ + int a[100]; + int length; + int i, t; + scanf("%d", &length); + for (i = 0; i < length; i++) + { + scanf("%d", &a[i]); + } + int target; + scanf("%d", &target); + t = findNumberInArray(a, length, target); + printf("%d", t); +} + + diff --git "a/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\344\270\211\351\242\230.c" "b/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\344\270\211\351\242\230.c" new file mode 100644 index 00000000..231db529 --- /dev/null +++ "b/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\344\270\211\351\242\230.c" @@ -0,0 +1,58 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +int f(int** matrix, int n, int m, int target) +{ + int i, j; + int count = 0; + for (i = 0; i < n; i++) + { + for (j = 0; j < m; j++) + { + if (matrix[i][j] == target) + { + count = count + 1; + } + } + } + return count; + +} +int main() +{ + int m, n, target; + scanf("%d%d%d", &n, &m, &target); + int i, j; + int** p = (int**)malloc(sizeof(int*) * n); + for (i = 0; i < n; i++) + { + p[i] = (int*)malloc(sizeof(int) * m); + } + for (i = 0; i < n; i++) + { + for (j = 0; j < m; j++) + { + scanf("%d", &p[i][j]); + } + } + int t; + t = f(p, n, m, target); + if (t != 0) + { + printf("true"); + } + else if (t == 0) + { + printf("false"); + } + for (i = 0; i < n; i++) + { + free(p[i]); + } + free(p); + return 0; +} + + + diff --git "a/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\344\272\214\351\242\230.c" "b/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\344\272\214\351\242\230.c" new file mode 100644 index 00000000..7764e7a4 --- /dev/null +++ "b/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\344\272\214\351\242\230.c" @@ -0,0 +1,39 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +int findNumbers(int* nums, int length) +{ + int i; + int count = 0; + for (i = 0; i < length; i++) + { + int num = 0; + while (nums[i]) + { + nums[i] /= 10; + num = num + 1; + } + if (num % 2 == 0) + { + count = count + 1; + } + } + return count; +} +int main() +{ + int i; + int a[100]; + int length; + int t; + scanf("%d", &length); + for (i = 0; i < length; i++) + { + scanf("%d", &a[i]); + } + t = findNumbers(a, length); + printf("%d", t); +} + + + diff --git "a/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\344\272\224\351\242\230.c" "b/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\344\272\224\351\242\230.c" new file mode 100644 index 00000000..e967ca9a --- /dev/null +++ "b/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\344\272\224\351\242\230.c" @@ -0,0 +1,44 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +#include +int f(int* arr, int length, int a, int b, int c) +{ + int i, j, k; + int count = 0; + for (i = 0; i < length - 2; i++) + { + for (j = i + 1; j < length - 1; j++) + { + for (k = j + 1; k < length; k++) + { + if (abs(arr[i] - arr[j]) <= a && abs(arr[j] - arr[k]) <= b && abs(arr[i] - arr[k]) <= c) + { + count++; + } + } + } + } + return count; +} +int main() +{ + int m, t; + int k[50]; + int* p = k; + int length; + scanf("%d", &length); + int a, b, c; + scanf("%d%d%d", &a, &b, &c); + for (m = 0; m < length; m++) + { + scanf("%d", &k[m]); + } + t = f(p, length, a, b, c); + printf("%d", t); + return 0; +} + + + + diff --git "a/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\345\205\255\351\242\230.c" "b/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\345\205\255\351\242\230.c" new file mode 100644 index 00000000..da1ba2fd --- /dev/null +++ "b/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\345\205\255\351\242\230.c" @@ -0,0 +1,36 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +int f(int* arr, int length) +{ + int i, j; + for (i = 0; i < length - 1; i++) + { + for (j = 0; j < length - 1 - i; j++) + { + if (arr[j] > arr[j + 1]) + { + int t; + t = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = t; + } + } + } +} +int main() +{ + int arr[50]; + int i, length; + scanf("%d", &length); + for (i = 0; i < length; i++) + { + scanf("%d", &arr[i]); + } + f(arr, length); + for (i = 0; i < length; i++) + { + printf("%d ", arr[i]); + } + return 0; +} \ No newline at end of file diff --git "a/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\345\233\233\351\242\230.c" "b/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\345\233\233\351\242\230.c" new file mode 100644 index 00000000..abadc7af --- /dev/null +++ "b/2020-Autumn/Backend/task_03/chenxiangwang0457/\347\254\254\345\233\233\351\242\230.c" @@ -0,0 +1,38 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include +void moveZeroes(int* nums, int length) +{ + int i; + int temp = 0; + for (i = 0; i < length; i++) + { + if (nums[i] == 0) + { + temp++; + } + else if (temp != 0) + { + nums[i - temp] = nums[i]; + nums[i] = 0; + } + } +} +int main() +{ + int a[100]; + int i; + int length; + scanf("%d", &length); + for (i = 0; i < length; i++) + { + scanf("%d", &a[i]); + } + moveZeroes(a, length); + for (i = 0; i < length; i++) + { + printf("%d ", a[i]); + } +} + +