-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathValidateTime.cs
More file actions
51 lines (45 loc) · 1.4 KB
/
ValidateTime.cs
File metadata and controls
51 lines (45 loc) · 1.4 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class StartUp
{
static void Main()
{
Solution p = new Solution();
Console.WriteLine(p.solution(1, 8, 3, 2, 6, 4));
Console.WriteLine(p.solution(2, 2, 2, 2, 6, 4));
Console.WriteLine(p.solution(1, 9, 9, 9, 9, 9));
Console.WriteLine(p.solution(1, -1, 3, 2, 6, 4));
}
}
class Solution
{
public string solution(int A, int B, int C, int D, int E, int F)
{
int[] myArray = new int[6] { A, B, C, D, E, F };
for (int i = 23; i > 0; i--)
{
for (int ii = 59; ii > 0; ii--)
{
for (int iii = 59; iii > 0; iii--)
{
if (compareTwoArrays(i, ii, iii, myArray))
{
return i.ToString() + ":" + ii.ToString() + ":" + iii.ToString();
}
}
}
}
return "NOT POSSIBLE";
}
public bool compareTwoArrays(int i, int ii, int iii, int[] myArray)
{
char[] A = (i.ToString() + ii.ToString() + iii.ToString()).ToCharArray();
char[] B = string.Join("", myArray.Select(a => a.ToString()).ToArray()).ToCharArray();
Array.Sort(A);
Array.Sort(B);
return (int.Parse(string.Join("", A)) == int.Parse(string.Join("", B)));
}
}