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

none #183

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

none #183

Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions 2020-Autumn/Backend/task_02/Lidong Zou/2-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<stdio.h>
#include<stdlib.h>
void merge(int* a, int m, int* b, int n)
{
int i = m - 1, j = n - 1;
int k = m + n - 1;
while (i >= 0 && j >= 0)
{
if (a[i] >= b[j])
{
a[k--] = a[i];
i--;
}
else
{
a[k--] = b[j];
j--;
}
}
while (j >= 0)
{
a[k--] = b[j];
j--;
}
}
int main()
{
int a[] = { 1,2,3,0,0,0 };
int b[] = { 2,5,6 };
merge(a, 3, b, 3);
for (int i = 0; i < 6; i++)
printf("%d", a[i]);
system("pause");
return 0;
}
42 changes: 42 additions & 0 deletions 2020-Autumn/Backend/task_02/Lidong Zou/2-2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include<stdio.h>
#include<stdlib.h>
int rotate(int** matrix, int n)
{
int a[15][15],m(0);
for(int i=0;i<n;i++)
for (int j = 0; j < n; j++)
{
a[j][n - 1 - i] = *(*matrix + m);
m++;
}
printf_s("����Ľ��Ϊ��\n");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
printf_s("%d ", a[i][j]);
}
printf_s("\n");
}
return 0;
}

int main()
{
int n(0);
printf_s("���������ı߳���");
scanf_s("%d", &n);
int* s;
s = (int*)malloc(n * n * sizeof(int));
if (s == NULL) exit(1);
for (int i = 1; i <= n * n; i++)
{
printf_s("�������%d������", i);
scanf_s("%d", (s + i - 1));
}
int** matrix;
matrix = &s;
rotate(matrix, n);
free((int*)s);
return 0;
}
23 changes: 23 additions & 0 deletions 2020-Autumn/Backend/task_02/Lidong Zou/2-3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<stdio.h>
int traversal1(int* a, int n)
{
for (int i = 0; i < n; i++)
printf_s("%d ", *(a + i));
return 0;
}
int main()
{
int a[20];
int n;
printf_s("����������Ĵ�С��");
scanf_s("%d", &n);
for (int i = 0; i < n; i++)
{
printf_s("�������%d������", i + 1);
scanf_s("%d", &a[i]);
}
int* p(a);
traversal1(p, n);
return 0;
}

20 changes: 20 additions & 0 deletions 2020-Autumn/Backend/task_02/Lidong Zou/2-4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>
#include<stdlib.h>
int* createArray(int n)
{
int* p;
p = (int*)malloc(n * sizeof(int));
if (p == NULL) exit(1);
for (int i = 0; i < n; i++)
*(p + i) = i + 1;
return p;
}
int main()
{
printf_s("����������Ķ�̬����Ĵ�С��");
int n;
scanf_s("%d", &n);
for (int i = 0; i < n; i++)
printf_s("%d ", *(createArray(n) + i));
return 0;
}
24 changes: 24 additions & 0 deletions 2020-Autumn/Backend/task_02/Lidong Zou/2-5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<stdio.h>
#include<stdlib.h>
int** createArray(int n, int m)
{
int** pp, * p;
pp = &p;
p = (int*)malloc(n * m * sizeof(int));
if (p == NULL) exit(1);
for (int i = 0; i < n * m; i++)
*(p + i) = i + 1;
return pp;
}
int main()
{
printf_s("����������ij������м��ö��Ÿ�������");
int n, m;
scanf_s("%d,%d", &n, &m);
for (int i = 0; i < n*m; i++)
{
printf_s("%d ", *(*createArray(n, m)+i));
if((i+1)%m==0) printf_s("\n");
}
return 0;
}
21 changes: 21 additions & 0 deletions 2020-Autumn/Backend/task_02/Lidong Zou/2-6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<stdio.h>
int sum(0);
int fac(int n)
{
if (n == 1) return sum + 1;
else if (n == 0) return sum;
else
{
sum += n;
n -= 2;
return fac(n);
}
}
int main()
{
printf_s("������̨�׵���Ŀ��");
int n;
scanf_s("%d", &n);
printf_s("һ����%d�ַ�����", fac(n));
return 0;
}
7 changes: 7 additions & 0 deletions 2020-Autumn/Backend/task_02/Lidong Zou/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#阴雨,考试,忙碌
#####关于第二次作业的总结
这两周事情都很多,高数的期中考试,英语四级的口语考试,两套英语四级卷子,一套雅思试卷,1500字军事理论,高数做也做不完的习题。
上面的这些内容表面上是抱怨,实则我想说,忙碌可以证明自己的存在感,也顺便解释一下这次任务交的比较晚的原因。
对于数组,指针,我是属于零基础,在刚上手的时候,完全属于不知所措,看到题目有自己的想法之后,也有一些相关的语句,语法是自己所不知道的,也借助了百度的帮忙。也就只有第六题寻求了一下安慰。
那么话归正题,这一次作业给我的经验就是要在完成任务之前,要了解相关的知识,我在这里说的知识是更进一步的知识,更基础的知识,一些铺垫性质的知识,这样才能更好去完成任务。

30 changes: 30 additions & 0 deletions 2020-Autumn/Backend/task_03/Lidong Zou/3-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<stdio.h>
#include<stdlib.h>
int findNumberInArray(int* arr, int length, int target)
{
int num(0);
for (int i = 0; i < length; i++)
if (*(arr + i) == target) num++;
return num;
}
int main()
{
int length;
printf_s("�������������");
scanf_s("%d", &length);
int* arr;
arr = (int*)malloc(length * sizeof(int));
if (arr == NULL) exit(1);
for (int i = 0; i < length; i++)
{
printf_s("�������%d������", i + 1);
scanf_s("%d", arr + i);
}
int target;
printf_s("������Ҫ���ҵ�����");
scanf_s("%d", &target);
printf_s("�ظ�����Ϊ%d��", findNumberInArray(arr, length, target));
return 0;
}


32 changes: 32 additions & 0 deletions 2020-Autumn/Backend/task_03/Lidong Zou/3-2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<stdio.h>
#include<stdlib.h>
int findNumbers(int* nums, int length)
{
int n(0);
for (int i = 0; i < length; i++)
if (*(nums + i) % 2 == 0) n++;
return n;
}
int main()
{
int length;
printf_s("����������Ĵ�С��");
scanf_s("%d", &length);
int* nums;
nums = (int*)malloc(length * sizeof(int));
if (nums == NULL) exit(0);
for (int i = 0; i < length; i++)
{
printf_s("�������%d�����ݣ�", i + 1);
scanf_s("%d", nums + i);
}
printf_s("λ��Ϊż���ĸ���Ϊ%d",findNumbers(nums, length));
return 0;
}







36 changes: 36 additions & 0 deletions 2020-Autumn/Backend/task_03/Lidong Zou/3-3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<stdio.h>
#include<stdlib.h>
bool findNumberIn2DArray(int** matrix, int n, int m, int target)
{
int a(0);
for (int i = 0; i < m; i++)
if (*(*matrix + n * i) <= target && *(*matrix + n * i + m - 1) >= target)
for (int j = n * i; j <= n * i + m - 1; j++)
if (*(*matrix + j) == target) a = 1;
if (a == 1) return true;
else return false;
}
int main()
{
int n, m;
printf_s("����������ij������м��ö��ŷָ�����");
scanf_s("%d,%d", &n, &m);
int* p;
p = (int*)malloc(n * m * sizeof(int));
if (p == NULL) exit(1);
printf_s("���������ݣ�Ҫ��ÿһ�ж����մ����ҵ�����˳������ÿһ�ж����մ��ϵ��µ�����˳������\n");
for (int i = 0; i < n * m; i++)
{
printf_s("��%d������", i + 1);
scanf_s("%d", p + i);
}
int target;
printf_s("���������Ŀ�꣺");
scanf_s("%d", &target);
int** pp;
pp = &p;
if (findNumberIn2DArray(pp,n,m,target) != 1)
printf_s("false");
else printf_s("true");
return 0;
}
33 changes: 33 additions & 0 deletions 2020-Autumn/Backend/task_03/Lidong Zou/3-4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<stdio.h>
#include<stdlib.h>
int moveZeroes(int* nums, int length)
{
int n(0);
for (int i = 0; i < length; i++)
if (*(nums + i) == 0)
{
for (int j = i; j < length-1; j++)
*(nums + j) = *(nums + j + 1);
*(nums + length - 1) = 0;
}
return 0;
}
int main()
{
int* nums, length;
printf_s("����������Ĵ�С��");
scanf_s("%d", &length);
nums = (int*)malloc(length * sizeof(int));
if (nums == NULL) exit(1);
printf_s("��������������\n");
for (int i = 0; i < length; i++)
{
printf_s("��%d��������", i + 1);
scanf_s("%d", nums + i);
}
moveZeroes(nums, length);
for (int i = 0; i < length; i++)
printf_s("%d ", *(nums + i));
free((int*)nums);
return 0;
}
33 changes: 33 additions & 0 deletions 2020-Autumn/Backend/task_03/Lidong Zou/3-5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int countGoodTriplets(int* arr, int length, int a, int b, int c)
{
int n(0);
for (int i = 0; i < length; i++)
for (int j = i + 1; j < length; j++)
if (fabs(*(arr + i) - *(arr + j)) <= a)
for (int k = j + 1; k < length; k++)
if (fabs(*(arr + j) - *(arr + k)) <= b && (fabs(*(arr + i) - *(arr + k)) <= c))
n++;
return n;
}
int main()
{
int length;
printf_s("�������������");
scanf_s("%d", &length);
int* arr;
arr = (int*)malloc(length * sizeof(int));
if (arr == NULL) exit(1);
for (int i = 0; i < length; i++)
{
printf_s("�������%d�����ݣ�", i + 1);
scanf_s("%d", arr + i);
}
int a, b, c;
printf_s("��ֱ�����a,b,c����ֵ���м��ö��ŷָ�����");
scanf_s("%d,%d,%d", &a, &b, &c);
printf_s("һ����%d������Ԫ�顣", countGoodTriplets(arr, length, a, b, c));
return 0;
}
33 changes: 33 additions & 0 deletions 2020-Autumn/Backend/task_03/Lidong Zou/3-6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<stdio.h>
#include<stdlib.h>
int sort(int* arr, int length)
{
int max(*arr), t(0), n;
for(int i=1;i<length;i++)
if (*(arr + i) > max)
{
max = *(arr + i);
t = i;
}
n = *(arr + t);
*(arr + t) = *(arr + length - 1);
*(arr + length - 1) = n;
return max;
}

int main()
{
int length, * arr;
printf_s("����������ij��ȣ�");
scanf_s("%d", &length);
arr = (int*)malloc(length * sizeof(int));
if (arr == NULL) exit(1);
for (int i = 0; i < length; i++)
{
printf_s("�������%d�����ݣ�", i + 1);
scanf_s("%d", arr + i);
}
for (int i = 0; i < length; i++)
printf_s("%d ", sort(arr, length - i));
return 0;
}
Binary file added 2020-Autumn/Backend/task_03/Lidong Zou/3-7.docx
Binary file not shown.
Loading