Time conversion program optimization
If you were writing this for real world use1, I think the right way would be to use std::get_time and std::put_time, something on this order:

#include &lt;iostream&gt;
#include &lt;iomanip&gt;
#include &lt;ctime&gt;

int main() {
    struct std::tm t;
    std::cin &gt;&gt; std::get_time(&amp;t, "%I:%M:%S%p");
    std::mktime(&amp;t);
    std::cout &lt;&lt; std::put_time(&amp;t, "%H:%M:%S");
}


(Note: it's open to question whether the call to mktime is really necessary here, but at worst it's still pretty harmless).

Switch Statement

Looking more specifically at your code, the thing that probably sticks out the most is the big switch statement. I'd eliminate that in favor of a tiny bit of math:

if (ampm == "PM")
    hours += 12;


Reading Delimiters

Right now, the code to initially read the data is made somewhat ugly and unreadable (and arguably failure-prone) by it's somewhat poor handling of delimiters. It currently just reads a character and assumes it's a delimiter. In real life, you probably want to at least compare what you read to what you expected so ensure that the input is correctly formatted (and react appropriately if it's not).

Personally, I think I'd write a little operator overload like this:

std::istream &amp;operator &gt;&gt; (std::istream &amp;is, char const *pat) {

    char ch;
    while (isspace(static_cast&lt;unsigned char&gt;(is.peek())))
        is.get(ch);

    while (*pat &amp;&amp; is &amp;&amp; *pat == is.peek() &amp;&amp; is.get(ch)) 
        ++pat;    

    // if we didn't reach the end of the pattern, matching failed (mismatch, premature EOF, etc.)
    if (*pat) {
        is.setstate(std::ios::failbit);
    }

    return is;
}


At least to me, this supports much cleaner code to read the data:

cin &gt;&gt; hour &gt;&gt; ":" &gt;&gt; minute &gt;&gt; ":" &gt;&gt; second &gt;&gt; ampm;


...and the operator overload takes care of reading data, comparing to what was passed, and setting the stream's failbit if it didn't match. As it stands right now, I've also included skipping any leading white-space like normal extraction operators do, but it would be trivial to eliminate that if you didn't want it (but it shouldn't make any difference for solving the HackerRank problem).




1. HackerRank is apparently using an old/broken standard library, so it won't accept this, even when you try to tell it you want to use C++14.