Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #define YEAR 6
- #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
- bool isPolindrome(std::string str) {
- return str == std::string(str.rbegin(), str.rend());
- }
- std::string createOutputPolindromes(std::string date) {
- return date.substr(0, 2) + "." + date.substr(2, 2) + "." + date.substr(4);
- }
- std::string createDate(const std::string& year, const std::string& month, const std::string& day) {
- return day + month + year;
- }
- std::vector<std::string> datePolindrom(std::string dateStart, std::string dateEnd) {
- std::vector<std::string> Polindromes;
- int currentYear = std::stoi(dateStart.substr(YEAR)) - 1;
- int lastYear = std::stoi(dateEnd.substr(YEAR));
- while (++currentYear < lastYear) {
- std::string currentStringYear = std::to_string(currentYear);
- std::string currentStringOriginalYear = currentStringYear;
- std::reverse(currentStringYear.begin(), currentStringYear.end());
- std::string LastFourNumsInTheYear = currentStringYear.substr(currentStringYear.length() - 4);
- std::string stringDay = LastFourNumsInTheYear.substr(0, 2);
- std::string stringMonth = LastFourNumsInTheYear.substr(2,2);
- int intDay = std::stoi(stringDay);
- int intMonth = std::stoi(stringMonth);
- if (intMonth == 2) {
- if (!((isleap(std::stoi(currentStringOriginalYear)) && intDay < 30) || (!isleap(std::stoi(currentStringOriginalYear)) && intDay < 29))) {
- continue;
- }
- }
- if ((0 < intDay && intDay <= (31 - (intMonth - 1) % 7 % 2)) && (0 < intMonth && intMonth < 13)) {
- std::string potincailPolindrome = createDate(currentStringOriginalYear, stringMonth, stringDay);
- if (isPolindrome(potincailPolindrome)) {
- std::string datePolindrome = createOutputPolindromes(potincailPolindrome);
- Polindromes.push_back(datePolindrome);
- }
- }
- }
- return Polindromes;
- }
- int main(){
- for (std::string str : datePolindrom("06.22.1000", "06.22.2261")) {
- std::cout << str << "\n";
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement