-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpracticep17.cpp
More file actions
74 lines (62 loc) · 1.61 KB
/
practicep17.cpp
File metadata and controls
74 lines (62 loc) · 1.61 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
// #include <iostream>
// using namespace std;
// //remove duplicate entries
// int main(){
// int n;
// cin>>n;
// int arr[n];
// for(int i=0;i<n;++i){
// cin>>arr[i];
// };
// int nd=0;
// int nodup[n];
// for (int i = 0; i < n; ++i) {
// bool isDuplicate = false;
// // Check if the current element has already appeared in nodup
// for (int j = 0; j < nd; ++j) {
// if (arr[i] == nodup[j]) {
// isDuplicate = true;
// break;
// }
// }
// if(!isDuplicate){
// nodup[nd++]=arr[i];
// };
// };
// for(int i=0;i<n;++i){
// cout<<nodup[i]<<" ";
// };
// };
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
// Input the elements into the array
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
int nd = 0;
int nodup[n];
// Loop over the original array
for (int i = 0; i < n; ++i) {
bool isDuplicate = false;
// Check if the current element arr[i] is already in nodup array
for (int j = 0; j < nd; ++j) {
if (arr[i] == nodup[j]) {
isDuplicate = true;
break;
}
}
// If not a duplicate, add it to nodup array
if (!isDuplicate) {//or if isDuplicate is false
nodup[nd++] = arr[i];//increasing nd after insertion
}
}
// Output the array after removing duplicates
for (int i = 0; i < nd; ++i) {
cout << nodup[i] << " ";
}
return 0;
}