C# Time Conversion [HackerRank]
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
class Result
{
public static string timeConversion(string s)
{
//뒤 2자리가 PM이면
if(s.Substring(s.Length-2,2)=="PM")
{
//앞자리 정수형으로 바꾸고 12가 아니면 12 더해줌.
int tmp = Convert.ToInt32(s.Substring(0,2));
if(tmp!=12) tmp = tmp+12;
return tmp.ToString() + s.Substring(2,s.Length-4);
}
//뒤 2자리가 AM이면
else
{
//앞자리 정수형으로 바꾸고 12면 "00"으로, 아니면 "0" 뒤에 수를 더함
int tmp = Convert.ToInt32(s.Substring(0,2));
if(tmp==12) return "00" + s.Substring(2,s.Length-4);
else return "0" + tmp.ToString() + s.Substring(2,s.Length-4);
}
}
}
class Solution
{
public static void Main(string[] args)
{
TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
string s = Console.ReadLine();
string result = Result.timeConversion(s);
textWriter.WriteLine(result);
textWriter.Flush();
textWriter.Close();
}
}
'개발공간' 카테고리의 다른 글
C# Number Line Jumps [HackerRank] (0) | 2021.09.09 |
---|---|
C# Apple and Orange [HackerRank] (0) | 2021.09.09 |
C# Birthday Cake Candles [HackerRank] (0) | 2021.08.31 |
C# Mini-Max Sum [HackerRank] (0) | 2021.08.31 |
C# Staircase [HackerRank] (0) | 2021.08.31 |
댓글