-
Notifications
You must be signed in to change notification settings - Fork 1
/
max_possible_time_24hr.cpp
70 lines (68 loc) · 1.24 KB
/
max_possible_time_24hr.cpp
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
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
string max_time(int A, int B, int C, int D)
{
vector<int> digits;
digits.push_back(A); digits.push_back(B); digits.push_back(C); digits.push_back(D);
sort(digits.begin(), digits.end());
string time;
bool flag = false;
int i;
//first element
for(i=digits.size()-1; i>=0; i--)
if(digits[i] <= 2) {
flag = true;
break;
}
if(flag)
{
flag = false;
time.push_back(digits[i] + 48);
digits.erase(digits.begin() + i);
//second element
for(i = digits.size()-1; i>=0; i--)
{
if(time[0] != '2') {
flag = true;
break;
}
else if(digits[i] <= 3) {
flag = true;
break;
}
}
if(flag)
{
flag = false;
time.push_back(digits[i] + 48);
digits.erase(digits.begin() + i);
time.push_back(':');
//third element
for(i = digits.size() - 1; i>=0; i--)
if(digits[i] <= 5) {
flag = true;
break;
}
if(flag)
{
time.push_back(digits[i] + 48);
digits.erase(digits.begin() + i);
//fourth element
time.push_back(digits[0] + 48);
}
}
}
if(flag)
return time;
else
return "NOT POSSIBLE";
}
int main()
{
int A, B, C, D;
cin >> A >> B >> C >> D;
cout << max_time(A, B, C, D) << endl;
return 0;
}