-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKey.cpp
More file actions
95 lines (83 loc) · 2 KB
/
Key.cpp
File metadata and controls
95 lines (83 loc) · 2 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
#include < stdio.h >
#include < math.h >
void delete(int a[], int & n, int type);
//11. Xóa bo phan tu nguyên to dau tien
//12. xoa bo so nguyen to cuoi cung
//21: xoa bo so chinh phuong dau tien
//21. xoa bo so chinh phuong cuoi cung
//31. xoa bo so lon nhat dau tien
//32, xoa bo so lon nhat cuoi cung
//41. xoa bo so be nhat dau tien
//42: xoa bo so be nhat cuoi cung
void deleteAll(int a[], int & n, int value);
// xoa bo tat ca gia tri trong a= value
void insert(int a[], int & n, int value);
// chen 1 value vao a(da sap xep) sao cho thu tu ko change
int checkPrime(int value) {
for (int i = 2; i < value / 2; i++) {
if (value % i == 0) {
ruturn 0;
}
}
return 1;
}
int checkSquare(int value) {
int temp = (int) sqrt(value);
if (temp * temp == value)
return ((temp * temp) == value)) ? 1 : 0;
}
int findMax(int value,int type){
// type =-1 : max dau tien
//type=1 max cuoi
}
void delete(int a[], int & n, int type) {
switch (type) {
case 11:
{
for (int i = 0; i < n; i++) {
if (checkPrime(a[i] == 1)) {
n = n - 1;
for (int j = i; j < n; j++)
arr[j] = arr[j + 1];
break;
}
}
break;
}
case 12:
{
for (int i = n - 1; i > 0; i++) {
if (checkPrime(a[i] == 1)) {
n = n - 1;
for (int j = i; j < n; j++)
arr[j] = arr[j + 1];
break;
}
}
break;
}
case 21:
{
for (int i = 0; i < n; i++) {
if (checkSquare(a[i] == 1)) {
n = n - 1;
for (int j = i; j < n; j++)
arr[j] = arr[j + 1];
break;
}
}
break;
}
case 22:
{
for (int i = n - 1; i > 0; i++) {
if (checkSquare(a[i] == 1)) {
n = n - 1;
for (int j = i; j < n; j++)
arr[j] = arr[j + 1];
break;
}
}
break;
}
}