My code is failing one test case according to my company software I cant find out what test case it is, as those test cases are hidden. The below Code converts meridian time format into military time format. I would like to not use the datetime functions of c# if possible and find out whats missing in this code itself
public static void Main()
{
string time = Console.ReadLine();
string timeHour = time.Substring(0,2);
string timeRest = time.Substring(2,6);
string meridian = time[8]+""+time[9];
string milTime = "";
// System.Console.WriteLine(meridian);
// System.Console.WriteLine(timeHour);
// System.Console.WriteLine(timeRest);
int a =0;
if(meridian == "PM")
{
if(timeHour != "12")
{
a = Convert.ToInt32(timeHour)+12;
}
else
{
a = 12;
}
}
else if(meridian == "AM")
{
if(timeHour != "12"){
a = Convert.ToInt32(timeHour);
}
else
{
a = 0;
}
}
// System.Console.WriteLine(a);
if(a !=0 )
{
milTime = a + timeRest;
}
else
{
milTime = "00" + timeRest;
}
System.Console.WriteLine(milTime);
}
Aucun commentaire:
Enregistrer un commentaire