-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTimeConversion.cs
87 lines (77 loc) · 2.53 KB
/
TimeConversion.cs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
//
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
/*
* Complete the timeConversion function below.
*/
static string timeConversion(string s) {
/*
* Write your code here.
*/
var ampm = s.Substring (s.Length-2);
var hours = s.Split(':')[0];
var mins = s.Split(':')[1];
var secs = s.Split(':')[2];
secs = secs.Substring(0,2);
var militaryTime = "";
if (ampm.Equals("PM")) {
switch (hours)
{
case "12":
militaryTime = "12" + ":" + mins + ":" + secs;
break;
case "01":
militaryTime = "13" + ":" + mins + ":" + secs;
break;
case "02":
militaryTime = "14" + ":" + mins + ":" + secs;
break;
case "03":
militaryTime = "15" + ":" + mins + ":" + secs;
break;
case "04":
militaryTime = "16" + ":" + mins + ":" + secs;
break;
case "05":
militaryTime = "17" + ":" + mins + ":" + secs;
break;
case "06":
militaryTime = "18" + ":" + mins + ":" + secs;
break;
case "07":
militaryTime = "19" + ":" + mins + ":" + secs;
break;
case "08":
militaryTime = "20" + ":" + mins + ":" + secs;
break;
case "09":
militaryTime = "21" + ":" + mins + ":" + secs;
break;
case "10":
militaryTime = "22" + ":" + mins + ":" + secs;
break;
case "11":
militaryTime = "23" + ":" + mins + ":" + secs;
break;
}
} else {
if (hours.Equals("12")) {
militaryTime = "00" + ":" + mins + ":" + secs;
} else{
militaryTime = hours + ":" + mins + ":" + secs;
}
}
return militaryTime;
}
static void Main(string[] args) {
TextWriter tw = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
string s = Console.ReadLine();
string result = timeConversion(s);
tw.WriteLine(result);
tw.Flush();
tw.Close();
}
}