-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSolution.cs
32 lines (25 loc) · 830 Bytes
/
Solution.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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
static string timeConversion(string s) {
var values = s.Split(':').Select(x => x.Substring(0,2)).ToList();
var isPM = s.Remove(0,8) == "PM";
var hours = int.Parse(values[0]);
if(isPM || hours == 12)
hours = (hours + 12)%24;
if(isPM && hours < 12)
hours += 12;
values[0] = hours.ToString("00");
return string.Join(":", values);
}
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();
}
}