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

第二次任务 #157

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions 2020-Autumn/Backend/task_02/Zeppel-Tao/1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
using namespace std;
//��һ��
void text01(int m, int n,int* arrA, int* arrB)
{
int i, j;
i = m - 1;
j = n - 1;
while (i >= 0 && j >= 0)
{
if (arrA[i] >= arrB[j]) //�Ӻ���ǰ���򣬽��ϴ��ֵ����A��
{
arrA[i + j + 1] = arrA[i];
i--;
}
else
{
arrA[i + j + 1] = arrB[j];
j--;
}
}
while (j >= 0)//��B����ʣ���ֵʱ����ʣ���ֵ����A��
//��ʣ�����A�е�ֵ����ֱ��������A��
{
arrA[j] = arrB[j];
}
}
int main()
{
int arrA[7] = { 1, 2, 3, 8, 0, 0, 0 };
int arrB[3] = { 2,5,6 };
text01(4, 3, arrA,arrB);
for (int i = 0; i < 7; i++)
{
cout << arrA[i] << " ";
}

system("pause");
return 0;
}
64 changes: 64 additions & 0 deletions 2020-Autumn/Backend/task_02/Zeppel-Tao/2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <iostream>
using namespace std;
void text02(int** matrix, int n)
{

cout << "��תǰ:" << endl;
for (int i = 0; i < n; i++)

{
for (int j = 0; j < n; j++)
{

matrix[i][j] = i * n + j + 1;
cout << matrix[i][j] << "\t";
}
cout << endl;
}
for (int i = 0; i < n / 2; i++)
{
for (int j = 0; j < n; j++)
{
int temp = matrix[i][j];
matrix[i][j] = matrix[n - i - 1][j];
matrix[n - i - 1][j] = temp;

}
}
//�Խ��߷�ת
for (int i = 0; i < n; i++)
{
for (int j = 0; j < i; j++)
{
int temp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = temp;
}
}
cout << "��ת��:" << endl;
for (int i = 0; i < n; i++)

{
for (int j = 0; j < n; j++)
{

cout << matrix[i][j] << "\t";
}
cout << endl;
}
}
int main()
{
int n = 0;
cout << "������n��";
cin >> n;
int** matrix;
matrix = new int* [n];
for (int i = 0; i < n; i++)
{
matrix[i] = new int[n];
}
text02(matrix, n);
system("pause");
return 0;
}
20 changes: 20 additions & 0 deletions 2020-Autumn/Backend/task_02/Zeppel-Tao/3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
using namespace std;
void text03(int* a, int n)
{
int size = 10000;
int* arr = new int[size];
int n = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
arr[i] = i;
cout << arr[i] << " ";
}
}
int main()
{

system("pause");
return 0;
}
25 changes: 25 additions & 0 deletions 2020-Autumn/Backend/task_02/Zeppel-Tao/4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
using namespace std;

int* text04(int n)
{
cin >> n;
int* arr = new int[n];
for (int i = 0; i < n; i++)
{
arr[i] = i + 1;
}

for (int i = 0; i < n; i++)
{
cout << arr[i] << "\t";
}
return arr;
}
int main()
{
int n = 0;
text04(n);
system("pause");
return 0;
}
40 changes: 40 additions & 0 deletions 2020-Autumn/Backend/task_02/Zeppel-Tao/5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
using namespace std;

int** text05(int m, int n)
{
int m = 0;
int n = 0;
cout << "����������: ";
cin >> m;
cout << "����������: ";
cin >> n;
int** arr = new int* [m];
for (int i = 0; i < m; i++)
{
arr[i] = new int[n];
}
for (int i = 0; i < m; i++)

{
for (int j = 0; j < n; j++)
{
arr[i][j] = i * n + j; //��ʹ��ָ����Ϊ*(*(arr+i)+j) cin >> arr[i][j]
cout << arr[i][j] << "\t";
}
cout << endl;
}
for (int i = 0; i < m; i++)
{
delete[] arr[i];
}
delete[] arr;
}
int main()
{
int m = 0;
int n = 0;
text05(m, n);
system("pause");
return 0;
}
29 changes: 29 additions & 0 deletions 2020-Autumn/Backend/task_02/Zeppel-Tao/6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
using namespace std;

int climbstairs(int n)
{
if (n == 0)
{
return 0;
}
else if (n == 1)
{
return 1;
}
else if (n == 2)
{
return 2;
}
else {
return climbstairs(n - 1) + climbstairs(n - 2); //ʹ�õݹ�
}
}
int main()
{
int n = 0;
cin >> n;
climbstairs(n);
system("pause");
return 0;
}
24 changes: 24 additions & 0 deletions 2020-Autumn/Backend/task_02/Zeppel-Tao/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 第二次任务总结

**1、学习和使用指针与数组**

**2、学习了时间复杂度与空间复杂度的概念**

**3、学习了动态数组的概念**

**4、了解了递归的概念**

*****

## 出现的问题

**1、开始时未弄明白动态数组的概念**

**2、多重指针的含义**

**3、不知该怎样去优化第一题的复杂度问题**





50 changes: 50 additions & 0 deletions 2020-Autumn/Backend/task_03/ZeppelI-Tao/1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <iostream>
using namespace std;

int findNumberInArray(int* arr, int length, int target, bool isleft)
{
int position = 0;
int left = 0;
int right = length - 1;

while (left <= right)
{
int mid = (left + right) / 2;
if (arr[mid] < target)
{
left = mid + 1;
}
else if (arr[mid] > target)
{
right = mid - 1;
}
else
{
position = mid;
if (isleft)//�ж������Ƿ���ͬ��������ȡ��λ��
{
right = mid - 1;
}
else
{
left = mid + 1;
}
}
}
return position;
}

int main()
{
int arr[] = { 1,2,3,4,4,4,4,5,6,7 } ;
int length = sizeof(arr) / sizeof(arr[0]);
int target = 0;
cout << "������Ҫ���ҵ����֣�";
cin >> target;
int low = findNumberInArray(arr, length, target, true);
int high = findNumberInArray(arr, length, target, false);
int sum = high - low + 1;
cout << "���ֹ��У�" << sum << " ��";
system("pause");
return 0;
}
34 changes: 34 additions & 0 deletions 2020-Autumn/Backend/task_03/ZeppelI-Tao/2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>
using namespace std;
//������
//���룺nums = [12, 345, 2, 6, 7896]
//�����2
//���ͣ�
//���ֻ�� 12 �� 7896 ��λ��Ϊż��������

int findNumbers(int* nums, int length)
{
int sum = 0;
int n = 0;
for (int i = 0; i < length; i++)
{
while (nums[i] > 0)
{
nums[i] /= 10;
n++;
}
if (n % 2 == 0)
{
sum++;
}
}
return sum;
}
int main()
{
int nums[] = { 12, 345, 2, 6, 7896 };
int length = sizeof(nums) / sizeof(nums[0]);
cout<<findNumbers(nums, length)<<endl;
system("pause");
return 0;
}
Loading