Skip to content

Commit

Permalink
Create TimeConversion.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnabBir authored May 13, 2019
1 parent 1d00f3a commit 94761ac
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions TimeConversion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <bits/stdc++.h>

using namespace std;

/*
* Complete the timeConversion function below.
*/

string getString(char x) {
string s(1, x);
return s;
}
string timeConversion(string s) {
int hr = stoi(s.substr(0,2));
if(s[s.length()-2] == 'A') {
if(hr == 12) {
return "00" + s.substr(2, 6);
}
else return s.substr(0, 8);
}
else {
if(hr == 12){
return s.substr(0, 8);
}
else return to_string(hr + 12) + s.substr(2, 6);
}
}

int main()
{
ofstream fout(getenv("OUTPUT_PATH"));

string s;
getline(cin, s);

string result = timeConversion(s);

fout << result << "\n";

fout.close();

return 0;
}

0 comments on commit 94761ac

Please sign in to comment.