Created
June 21, 2019 06:35
-
-
Save kei9327/7ae7be23e58c9943def1508ac21a1df8 to your computer and use it in GitHub Desktop.
HackerRank>Algorithm>implementation>dayOfProgrammer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
bool isLeap(int year); | |
string ltrim(const string &); | |
string rtrim(const string &); | |
// Complete the dayOfProgrammer function below. | |
string dayOfProgrammer(int year) { | |
if( year == 1918 ) return "26.09.1918"; | |
if( isLeap( year ) ) return "12.09." + std::to_string(year); | |
else return "13.09." + std::to_string(year); | |
} | |
bool isLeap( int year ) { | |
if( year % 4 != 0 ) return false; | |
if( year > 1918 && year % 100 == 0 && year % 400 != 0 ) return false; | |
return true; | |
} | |
int main() | |
{ | |
ofstream fout(getenv("OUTPUT_PATH")); | |
string year_temp; | |
getline(cin, year_temp); | |
int year = stoi(ltrim(rtrim(year_temp))); | |
string result = dayOfProgrammer(year); | |
fout << result << "\n"; | |
fout.close(); | |
return 0; | |
} | |
string ltrim(const string &str) { | |
string s(str); | |
s.erase( | |
s.begin(), | |
find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace))) | |
); | |
return s; | |
} | |
string rtrim(const string &str) { | |
string s(str); | |
s.erase( | |
find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(), | |
s.end() | |
); | |
return s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment