Skip to content

Commit 2ea0ed8

Browse files
Merge pull request #371 from Apoorv-Gaurav-Agarwal/patch-1
Created OptimalStoppingProblem.cpp
2 parents 41d11c9 + 770beba commit 2ea0ed8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

C++/OptimalStoppingProblem.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <iostream>
2+
#include <time.h>
3+
#include <cmath>
4+
#define e 2.71828
5+
using namespace std;
6+
7+
void printBestCandidate(int candidate[], int n)
8+
{
9+
int sample_size = round(n/e);
10+
cout << "\n\nSample size is " << sample_size << endl;
11+
int best = 0;
12+
for (int i = 1; i < sample_size; i++)
13+
if (candidate[i] > candidate[best])
14+
best = i;
15+
for (int i = sample_size; i < n; i++)
16+
if (candidate[i] >= candidate[best]) {
17+
best = i;
18+
break;
19+
}
20+
if (best >= sample_size)
21+
cout << endl << "Best candidate found is "
22+
<< best + 1 << " with talent "
23+
<< candidate[best] << endl;
24+
else
25+
cout << "Couldn't find a best candidate\n";
26+
}
27+
28+
int main()
29+
{
30+
int n;
31+
cin >> n;
32+
int candidate[n];
33+
cout << "Enter number of talents of the candidates\n";
34+
for (int i = 0; i < n; i++)
35+
cin >> candidate[i];
36+
cout << "Candidate : ";
37+
for (int i = 0; i < n; i++)
38+
cout << i + 1 << " ";
39+
cout << endl;
40+
cout << " Talents : ";
41+
for (int i = 0; i < n; i++)
42+
cout << candidate[i] << " ";
43+
printBestCandidate(candidate, n);
44+
return 0;
45+
}

0 commit comments

Comments
 (0)