diff --git a/2020-Autumn/Backend/task_02/Zeppel-Tao/1.cpp b/2020-Autumn/Backend/task_02/Zeppel-Tao/1.cpp new file mode 100644 index 00000000..8db0ce8b --- /dev/null +++ b/2020-Autumn/Backend/task_02/Zeppel-Tao/1.cpp @@ -0,0 +1,40 @@ +#include +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; +} \ No newline at end of file diff --git a/2020-Autumn/Backend/task_02/Zeppel-Tao/2.cpp b/2020-Autumn/Backend/task_02/Zeppel-Tao/2.cpp new file mode 100644 index 00000000..f6345c0a --- /dev/null +++ b/2020-Autumn/Backend/task_02/Zeppel-Tao/2.cpp @@ -0,0 +1,64 @@ +#include +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; +} \ No newline at end of file diff --git a/2020-Autumn/Backend/task_02/Zeppel-Tao/3.cpp b/2020-Autumn/Backend/task_02/Zeppel-Tao/3.cpp new file mode 100644 index 00000000..f1b93e67 --- /dev/null +++ b/2020-Autumn/Backend/task_02/Zeppel-Tao/3.cpp @@ -0,0 +1,20 @@ +#include +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; +} \ No newline at end of file diff --git a/2020-Autumn/Backend/task_02/Zeppel-Tao/4.cpp b/2020-Autumn/Backend/task_02/Zeppel-Tao/4.cpp new file mode 100644 index 00000000..d8cf45e1 --- /dev/null +++ b/2020-Autumn/Backend/task_02/Zeppel-Tao/4.cpp @@ -0,0 +1,25 @@ +#include +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; +} \ No newline at end of file diff --git a/2020-Autumn/Backend/task_02/Zeppel-Tao/5.cpp b/2020-Autumn/Backend/task_02/Zeppel-Tao/5.cpp new file mode 100644 index 00000000..f60ecc4b --- /dev/null +++ b/2020-Autumn/Backend/task_02/Zeppel-Tao/5.cpp @@ -0,0 +1,40 @@ +#include +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; +} \ No newline at end of file diff --git a/2020-Autumn/Backend/task_02/Zeppel-Tao/6.cpp b/2020-Autumn/Backend/task_02/Zeppel-Tao/6.cpp new file mode 100644 index 00000000..5260a84e --- /dev/null +++ b/2020-Autumn/Backend/task_02/Zeppel-Tao/6.cpp @@ -0,0 +1,29 @@ +#include +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; +} \ No newline at end of file diff --git a/2020-Autumn/Backend/task_02/Zeppel-Tao/README.md b/2020-Autumn/Backend/task_02/Zeppel-Tao/README.md new file mode 100644 index 00000000..09ffb295 --- /dev/null +++ b/2020-Autumn/Backend/task_02/Zeppel-Tao/README.md @@ -0,0 +1,24 @@ +# 第二次任务总结 + +**1、学习和使用指针与数组** + +**2、学习了时间复杂度与空间复杂度的概念** + +**3、学习了动态数组的概念** + +**4、了解了递归的概念** + +***** + +## 出现的问题 + +**1、开始时未弄明白动态数组的概念** + +**2、多重指针的含义** + +**3、不知该怎样去优化第一题的复杂度问题** + + + + + diff --git a/2020-Autumn/Backend/task_03/ZeppelI-Tao/1.cpp b/2020-Autumn/Backend/task_03/ZeppelI-Tao/1.cpp new file mode 100644 index 00000000..d8c40457 --- /dev/null +++ b/2020-Autumn/Backend/task_03/ZeppelI-Tao/1.cpp @@ -0,0 +1,50 @@ +#include +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; +} \ No newline at end of file diff --git a/2020-Autumn/Backend/task_03/ZeppelI-Tao/2.cpp b/2020-Autumn/Backend/task_03/ZeppelI-Tao/2.cpp new file mode 100644 index 00000000..671e7158 --- /dev/null +++ b/2020-Autumn/Backend/task_03/ZeppelI-Tao/2.cpp @@ -0,0 +1,34 @@ +#include +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< +using namespace std; + +bool findNumberIn2DArray(int arr[][5], int n, int m, int target) +{ + int i = 0; + int j = m-1; + while (i <= n-1 && i >= 0 && j <= m-1 && j >= 0) + { + if (arr[i][j] > target) + { + j--; + } + else if (arr[i][j] < target) + { + i++; + } + else if (arr[i][j] == target) + { + return true; + } + return false; + } +} + +int main() +{ + const int m = 5; + const int n = 5; + int target = 0; + cout << "������Ŀ������: "; + cin >> target; + int arr[n][m] = + { + {1, 4, 7, 11, 15}, + {2, 5, 8, 12, 19}, + {3, 6, 9, 16, 22}, + {10, 13, 14, 17, 24}, + {18, 21, 23, 26, 30} + }; + bool ret = findNumberIn2DArray(arr, n, m,target); + if (ret) + { + cout << "true" << endl; + } + else + { + cout << "false" << endl; + } + system("pause"); + return 0; +} +//[ +// [1, 4, 7, 11, 15], +// [2, 5, 8, 12, 19], +// [3, 6, 9, 16, 22], +// [10, 13, 14, 17, 24], +// [18, 21, 23, 26, 30] +//] +//���� target = 5������ true�� +//���� target = 20������ false�� \ No newline at end of file diff --git a/2020-Autumn/Backend/task_03/ZeppelI-Tao/4.cpp b/2020-Autumn/Backend/task_03/ZeppelI-Tao/4.cpp new file mode 100644 index 00000000..4d510cba --- /dev/null +++ b/2020-Autumn/Backend/task_03/ZeppelI-Tao/4.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; +void moveZeroes(int* nums, int length) +{ + int k = length - 1; + int sum0 = 0; + for (int i = 0; i < length-1 ; i++) + { + if (nums[i] == 0) + { + for (int j = i; j < length - i - 1; j++) + { + nums[j] = nums[j + 1]; + } + sum0++; + } + + } + for (int j = 0;j < sum0; j++) + { + nums[k] = 0; + k--; + } +} +int main() +{ + int* arr = new int[5]{ 0,1,0,3,12 }; + moveZeroes(arr,5); + for (int i = 0; i <5 ; i++) + { + cout << arr[i] << endl; + } + system("pause"); + return 0; +} +//void moveZeroes(int* nums, int length){ +//code +//} +//����: nums = [0, 1, 0, 3, 12], length = 5 + +//��� : [1, 3, 12, 0, 0] diff --git a/2020-Autumn/Backend/task_03/ZeppelI-Tao/5.cpp b/2020-Autumn/Backend/task_03/ZeppelI-Tao/5.cpp new file mode 100644 index 00000000..3895b32a --- /dev/null +++ b/2020-Autumn/Backend/task_03/ZeppelI-Tao/5.cpp @@ -0,0 +1,60 @@ +#include +#include +using namespace std; + + +int countGoodTriplets(int* arr, int length, int a, int b, int c) +{ + int sum = 0; + for (int i = 0; i < length - 2; i++) + { + for (int j = i+1; j < length - 1; j++) + { + for (int k = j + 1; k < length; k++) + { + if ((i + j + k ) > length) + { + continue; + } + else + { + int tempa = arr[i] - arr[j]; + int tempb = arr[j] - arr[k]; + int tempc = arr[i] - arr[k]; + if ((abs(arr[i] - arr[j]) < a || abs(arr[i] - arr[j]) == a) && (abs(arr[j] - arr[k]) < b || abs(arr[j] - arr[k]))&&(abs(arr[i] - arr[k])> a >> b >> c; + cout << countGoodTriplets(arr, length, a, b, c); + system("pause"); + return 0; +} +//�����Ԫ��(arr[i], arr[j], arr[k]) ��������ȫ������������Ϊ����һ�� ����Ԫ�� �� +//0 <= i < j < k < arr.length +// | arr[i] - arr[j]| <= a +// | arr[j] - arr[k]| <= b +// | arr[i] - arr[k]| <= c +// ���� | x | ��ʾ x �ľ���ֵ�� +// +// ������ +// ���룺arr = [3, 0, 1, 1, 9, 7], a = 7, b = 2, c = 3 +// �����4 +// ���ͣ�һ���� 4 ������Ԫ�飺[(3, 0, 1), (3, 0, 1), (3, 1, 1), (0, 1, 1)] �� +// +// �ο��ύ������ʽ +// int countGoodTriplets(int* arr, int length, int a, int* arr, int lengthb, int c) { +// //code +//} \ No newline at end of file diff --git a/2020-Autumn/Backend/task_03/ZeppelI-Tao/6.cpp b/2020-Autumn/Backend/task_03/ZeppelI-Tao/6.cpp new file mode 100644 index 00000000..ae19362a --- /dev/null +++ b/2020-Autumn/Backend/task_03/ZeppelI-Tao/6.cpp @@ -0,0 +1,47 @@ +#include +using namespace std; +//ʹ�ÿ�������ķ�����������ʱ�临�ӶȲ�����n^2 +void quickSort(int arr[], int left, int right) +{ + if (left >= right) //�ж��Ƿ������������������� + { + return; + } + int i, j, k; + i = left; + int base = arr[i]; //���û�׼�������ڻ�׼����ֵ�������Ҳ� + j = right; //С�ڻ�׼���ֵ��������� + while (i < j) + { //�����û�׼��λ�����ʱ����������Ҳ࿪ʼ���� + while (arr[j] >= base && i < j) + { + j--; //���ұ߿�ʼ�����������ֵ��������С�����ֵ�㱣�� + } + while (arr[i] <= base && i < j) + { + i++; + } + if (i < j) //�����ұ�����ֵ������ʹ�û�׼�����Ҿ�ΪС��||�������ֵ + { + int temp = arr[j]; + arr[j] = arr[i]; + arr[i] = temp; + } + } + arr[left] = arr[i]; //��׼����λ + arr[i] = base; + quickSort(arr, left, i - 1); //�ݹ���� + quickSort(arr, i + 1, right); //�ݹ��ұ� +} +int main() +{ + int arr[10] = { 3,15,8,6,22,48,1,96,71,0 }; + quickSort(arr, 0, 9); + for (int i = 0; i < 10; i++) + { + cout << arr[i] << endl; + } + + system("pause"); + return 0; +} \ No newline at end of file diff --git a/2020-Autumn/Backend/task_03/ZeppelI-Tao/7.md b/2020-Autumn/Backend/task_03/ZeppelI-Tao/7.md new file mode 100644 index 00000000..6e9ba91f --- /dev/null +++ b/2020-Autumn/Backend/task_03/ZeppelI-Tao/7.md @@ -0,0 +1,3 @@ +# 1000瓶水,有一瓶是毒药,你有10只小白鼠,喝了毒药一个礼拜后毒发,怎样在一周内知道哪瓶水有毒。 + +通过将一千瓶水每瓶标号,使用**二进制**的方式将其表示,将每个二进制位数为1的混合喂给小白鼠,最后观测所有小白鼠的状况,若死亡,则该小白鼠的位数上的值为1,反之为0,最终结合十只小白鼠的情况,得知有毒的。 \ No newline at end of file diff --git a/2020-Autumn/Backend/task_03/ZeppelI-Tao/Readme.md b/2020-Autumn/Backend/task_03/ZeppelI-Tao/Readme.md new file mode 100644 index 00000000..487bdcde --- /dev/null +++ b/2020-Autumn/Backend/task_03/ZeppelI-Tao/Readme.md @@ -0,0 +1,5 @@ +# 第三次任务总结 + +* 第七题智力题是在网上查找的答案 +* 无法想到更好的方法去降低时间复杂度 +* 第八题只能想出使用冒泡排序让时间复杂度为n^2排序后再让每个后一项减前一项得到值赋到max中,然后使用if语句判断大小。 \ No newline at end of file