-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathluu.cpp
More file actions
119 lines (105 loc) · 2.47 KB
/
luu.cpp
File metadata and controls
119 lines (105 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*#include <iostream>
using namespace std;
int main(){
int m,n;
cin>>n>>m;
int **a=new int*[n]; // cấp phát mảng 2 chiều
for (int i=0;i<n;i++)
for (int j=0;j<m,j++)
{
cin>>a[i][j];
a[i]=*(a+i);
a[i][j]=*(a[i]+j)=*(*(a+i)+j);
}
}*/
/*
test.cpp
TEST1.
bool* isHigher(int* arr, int num, int thres) {
bool* result = new bool[num]; // cấp phát mảng bool
for (int i = 0; i < num; i++) {
if (arr[i] >= thres) {
result[i] = true;
} else {
result[i] = false;
}
}
return result;
}
TEST2.
int** keepEven(int** matrix, int nRows, int nCols) {
// Bước 1: Tạo ma trận mới
int** newMatrix = new int*[nRows];
for (int i = 0; i < nRows; ++i) {
newMatrix[i] = new int[nCols];
}
// Bước 2: Duyệt qua từng phần tử
for (int i = 0; i < nRows; ++i) {
for (int j = 0; j < nCols; ++j) {
if (*(*(matrix+i)+j) % 2 == 0) {
newMatrix[i][j] = matrix[i][j];
} else {
newMatrix[i][j] = 0;
}
}
}
// Bước 3: Trả về ma trận mới
return newMatrix;
}
TEST3.
int ** getImage(int nRows, int nCols){
int **kq=new int *[nRows];
for (int i=0;i<nRows;i++){
kq[i]=new int [nCols];
for(int j=0;j<nCols;j++){
cin>>*(*(kq+i)+j);
}
}
return kq;
}
void fillImage(int** image,int nRows, int nCols, int threshold){
for(int i=0;i<nRows;i++){
for (int j=0;j<nCols;j++){
if(*(*(image+i)+j)<threshold) image[i][j]=0;
}
}
}
void print(int** image, int nRows, int nCols){
for(int i=0;i<nRows;i++){
for(int j=0;j<nCols;j++){
cout<<*(*(image+i)+j)<<" ";
}
cout<<endl;
}
}
TEST4.
int * merge(int* firstArr, int lenArr1, int* secondArr, int lenArr2)
{
int len=lenArr1+lenArr2;
int *kq=new int [len];
for(int i=0;i<len;i++){
if(i<lenArr1) {
kq[i]=firstArr[i];
} else {
kq[i]=secondArr[i - lenArr1]; // sửa ở đây
}
}
bool kt=false;
if(firstArr[1]<firstArr[4])kt=true;
if(kt==true){
for(int i=0;i<len;i++){
for(int j=i;j<len;j++){
if(kq[i]>kq[j]) swap(kq[i],kq[j]);
}
}}
else {
for(int i=0;i<len;i++){
for(int j=i;j<len;j++){
if(kq[i]<kq[j]) swap(kq[i],kq[j]);
}
}
}
return kq;
}
TEST5.
*/