Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <cstdlib>
- #include <string>
- using namespace std;
- /*
- * Complete the timeConversion function below.
- */
- string timeConversion(string s) {
- /*
- * Write your code here.
- */
- string a;
- a = s.at(0);
- string b;
- b = s.at(1);
- string aorp;
- aorp = s.at(s.size()-2);
- string c = a + b;
- int number = atoi (c.c_str());
- string out;
- if (aorp == "P" && number != 12)
- {
- number = number + 12;
- }
- else if (to_string(number).size() < 10)
- {
- out = "0";
- }
- out = out + to_string(number);
- for (int i = 2 ; i < s.size() -2; i = i +1)
- {
- out = out + s.at(i);
- }
- return out;
- }
- int main()
- {
- ofstream fout(getenv("OUTPUT_PATH"));
- string s;
- getline(cin, s);
- string result = timeConversion(s);
- fout << result << "\n";
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement