+ 5
Military Time Problem
My code fails on case 3 and 5, can anyone tell me what's wrong with the code string[] numin = Console.ReadLine().Split(':',' '); if (numin[2].Contains('P')) { int numout = Convert.ToInt32(numin[0]); numout += 12; string numouts = Convert.ToString(numin[1]); Console.Write(numout); Console.Write(':') Console.Write(numouts[0]); Console.Write(numouts[1]); } else if (numin[2].Contains('A')) { Console.Write(numin[0]); Console.Write(':'); Console.Write(numin[1]); };
22 Answers
+ 10
OK. I missed one more..
If it single digit like 8:00 AM output should be like 08:00
+ 28
Notice:
Single digits in left side like 8:00
00:00 am
00:00 pm
00:20 am
00:20 pm
Your code must output right for these examples
+ 8
Paste code in code playground save code and share your code link here. That will make easy to find out errors..
For input 12:20pm your output 24:20
it should be 12:20 only..
+ 4
If input is 12:10am you need output 0:10 as output... If 12:05pm then you have output 12:05 only...
By with your code what you getting..?
+ 3
OK. Fine..
Well come...
+ 3
t = input()
hour = 0
if t[1] == ':':
hour = int(t[0])
else:
hour = int(t[0:2])
if t[len(t)-2:] == 'PM':
if hour < 12:
hour += 12
elif t[len(t)-2:] == 'AM':
if hour < 12:
hour = hour
else:
pass
total_time = ''
if t[len(t)-2:] == 'PM':
total_time = str(hour) + ':' + t[len(t)-5:len(t)-3]
elif t[1] == ':' and t[len(t)-2:] == 'AM':
total_time = '0' + str(hour) + ':' + t[len(t)-5:len(t)-3]
elif t[2] == ':' and t[len(t)-2:] == 'AM' and t[0] == '0':
total_time = '0' + str(hour) + ':' + t[len(t)-5:len(t)-3]
elif t[2] == ':' and t[len(t)-2:] == 'AM':
total_time = str(hour) + ':' + t[len(t)-5:len(t)-3]
else : pass
print(total_time)
+ 2
Jayakrishna still nothing
string[] numin = Console.ReadLine().Split(':',' ');
if (numin[2].Contains('P'))
{
int numout = Convert.ToInt32(numin[0]);
numout += 12;
string numouts = Convert.ToString(numin[1]);
Console.Write(numout); Console.Write(':');
Console.Write(numouts[0]); Console.Write(numouts[1]);
}
else if (numin[2].Contains('A'))
{
int bollout = Convert.ToInt32(numin[0]);
if (bollout != 12)
{
Console.Write(numin[0]);
Console.Write(':');
Console.Write(numin[1]);
}
else
{
Console.Write("00");
Console.Write(':');
Console.Write(numin[1]);
}
};
+ 2
After numout value assigning change like this... And check again...
if(numout!=12)
numout += 12;
+ 2
It didn't work did it work for u?
+ 2
Do you changed above one.? . I done it java. Let me see description..
What is error? .
+ 2
It's not an error it fails the cases
+ 2
Yes it worked thank you
https://code.sololearn.com/cHjX1md9oA69/?ref=app
+ 2
Flayer i faced the same problem,
The problem is if the input is of single digit then we need to print output with an additional 0,
I.e. 6:45 AM
Op - 0645
check this,
https://www.sololearn.com/Discuss/2135879/?ref=app
+ 2
Akash Sil I have already fixed it just do something like
If input[0] < 10 write("0") before the actually result
+ 1
There is an easier way to write this. Check it ;).
https://code.sololearn.com/csvOritrsLMi
+ 1
DateTime is one of the things I hate the most in c# Jolanta Malinowska but thanks
0
Hlo
0
Hlw
0
Jolanta Malinowska you have to send a playground link not a coach cuz I can't see it