Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

合并数组 #158

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b501f79
Create chenxiangwang0457
chenxiangwang0457 Nov 11, 2020
9815da6
Create 合并数组
chenxiangwang0457 Nov 11, 2020
7171ce2
Delete 合并数组
chenxiangwang0457 Nov 11, 2020
0e3794e
Delete chenxiangwang0457
chenxiangwang0457 Nov 11, 2020
f624911
Create 第一题
chenxiangwang0457 Nov 11, 2020
8f29f28
Update 第一题
chenxiangwang0457 Nov 11, 2020
f515372
Create 第二题
chenxiangwang0457 Nov 11, 2020
612c48a
Update 第二题
chenxiangwang0457 Nov 12, 2020
2a9ad95
Create 第三题
chenxiangwang0457 Nov 15, 2020
4c97fc8
Create 第四题
chenxiangwang0457 Nov 15, 2020
f1f3e4b
Create 第五题
chenxiangwang0457 Nov 15, 2020
325a029
Delete 第二题
chenxiangwang0457 Nov 15, 2020
78f9404
Create 第二题
chenxiangwang0457 Nov 15, 2020
3fed9b7
Update 第五题
chenxiangwang0457 Nov 15, 2020
2362d03
Update 第五题
chenxiangwang0457 Nov 21, 2020
3588eab
Create README.md
chenxiangwang0457 Nov 21, 2020
15155ba
Update README.md
chenxiangwang0457 Nov 21, 2020
fcbe85d
Update README.md
chenxiangwang0457 Nov 21, 2020
005445b
Update README.md
chenxiangwang0457 Nov 21, 2020
c66c067
Update 第五题
chenxiangwang0457 Nov 21, 2020
df2a52a
第二题
chenxiangwang0457 Nov 21, 2020
1674275
测试
chenxiangwang0457 Nov 21, 2020
aad3ea6
Update task_02.cpp
chenxiangwang0457 Nov 21, 2020
840ef42
Update task_02.cpp
chenxiangwang0457 Nov 21, 2020
bcd2e15
Delete 源.c
chenxiangwang0457 Nov 21, 2020
7630126
test
chenxiangwang0457 Nov 21, 2020
425edb7
test
chenxiangwang0457 Nov 21, 2020
36ada77
测试
chenxiangwang0457 Nov 21, 2020
8057bd9
Update task_02.cpp
chenxiangwang0457 Nov 24, 2020
0bc3980
Update task_02.cpp
chenxiangwang0457 Nov 24, 2020
91d79e9
单个cpp的提交
chenxiangwang0457 Dec 1, 2020
e71d8d2
第三次任务
chenxiangwang0457 Dec 24, 2020
db0da3d
Create README.md
chenxiangwang0457 Dec 24, 2020
ff1f832
Create chenxiangwang0457
chenxiangwang0457 Dec 24, 2020
ab8edf8
Delete chenxiangwang0457
chenxiangwang0457 Dec 24, 2020
0a1c2fa
Update README.md
chenxiangwang0457 Dec 24, 2020
2f0439c
Update 第五题.cpp
chenxiangwang0457 Dec 27, 2020
debc00b
修改
chenxiangwang0457 Feb 7, 2021
6ee8d9e
Delete 第一题.c
chenxiangwang0457 Feb 7, 2021
0c8c480
Delete 第三题.c
chenxiangwang0457 Feb 7, 2021
f43004a
Delete 第二题.c
chenxiangwang0457 Feb 7, 2021
0d7e204
Delete 第四题.c
chenxiangwang0457 Feb 7, 2021
77b0f76
Delete 第六题.c
chenxiangwang0457 Feb 7, 2021
525d0dc
Delete 第五题.c
chenxiangwang0457 Feb 7, 2021
bce93e0
Delete README.md
chenxiangwang0457 Feb 7, 2021
0484ca9
Update RADEME.md
chenxiangwang0457 Feb 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions 2020-Autumn/Backend/task_02/chenxiangwang0457/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**这次任务,我学习了动态数组的创建使用,学习了用指针来访问数组;**




*创建完动态数组,千万不要忘记free*
35 changes: 35 additions & 0 deletions 2020-Autumn/Backend/task_02/chenxiangwang0457/第一题.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<stdio.h>
#include<stdlib.h>
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]);
}
}


14 changes: 14 additions & 0 deletions 2020-Autumn/Backend/task_02/chenxiangwang0457/第三题.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<stdio.h>
#include<stdlib.h>
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);
}

66 changes: 66 additions & 0 deletions 2020-Autumn/Backend/task_02/chenxiangwang0457/第二题.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
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;

}



35 changes: 35 additions & 0 deletions 2020-Autumn/Backend/task_02/chenxiangwang0457/第五题.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
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");
}
}
28 changes: 28 additions & 0 deletions 2020-Autumn/Backend/task_02/chenxiangwang0457/第四题.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
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));
}

}




1 change: 1 addition & 0 deletions 2020-Autumn/Backend/task_03/chenxiangwang0457/RADEME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*之后会对关键代码处作出注释;做题过程中容易忽略局部变量在循环中的位置,之后会仔细思考;注意函数名称*
33 changes: 33 additions & 0 deletions 2020-Autumn/Backend/task_03/chenxiangwang0457/第一题.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
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);
}


58 changes: 58 additions & 0 deletions 2020-Autumn/Backend/task_03/chenxiangwang0457/第三题.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
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;
}



39 changes: 39 additions & 0 deletions 2020-Autumn/Backend/task_03/chenxiangwang0457/第二题.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
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);
}



44 changes: 44 additions & 0 deletions 2020-Autumn/Backend/task_03/chenxiangwang0457/第五题.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
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;
}




Loading