-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbai2.cpp
More file actions
61 lines (56 loc) · 882 Bytes
/
bai2.cpp
File metadata and controls
61 lines (56 loc) · 882 Bytes
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
#include <iostream>
using namespace std;
void check(int arr[], int check[], int n)
{
for (int i = 0; i < n - 1; i++)
{
for (int j = i + 1; j < n; j++)
{
if (arr[i] == arr[j] && check[j] == 1)
{
check[i]++;
check[j] = 0;
}
}
}
}
void writeArray(int arr[], int check[], int n)
{
for (int i = 0; i < n; i++)
{
cin >> arr[i];
check[i] = 1;
}
}
void printArray(int a[], int n)
{
for (int i = 0; i < n; i++)
{
cout << a[i] << '\t';
}
}
void printMaxFrequent(int arr[], int check[], int n)
{
int vt = 0;
int max = check[0];
for (int i = 0; i < n; i++)
{
if (check[i] > max)
{
max = check[i];
vt = i;
}
}
cout << arr[vt];
}
int main()
{
int n;
cin >> n;
int arr[200000], frequent[200000];
writeArray(arr, frequent, n);
check(arr, frequent, n);
printArray(frequent, n);
cout << endl;
printMaxFrequent(arr, frequent, n);
}