Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #define YEAR 6
  5. #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
  6.  
  7. bool isPolindrome(std::string str) {
  8.     return str == std::string(str.rbegin(), str.rend());
  9. }
  10.  
  11.  
  12. std::string createOutputPolindromes(std::string date) {
  13.     return date.substr(0, 2) + "." + date.substr(2, 2) + "." + date.substr(4);
  14. }
  15.  
  16. std::string createDate(const std::string& year, const std::string& month, const std::string& day) {
  17.     return day + month + year;
  18. }
  19.  
  20.  
  21. std::vector<std::string> datePolindrom(std::string dateStart, std::string dateEnd) {
  22.     std::vector<std::string> Polindromes;
  23.  
  24.  
  25.     int currentYear = std::stoi(dateStart.substr(YEAR)) - 1;
  26.     int lastYear = std::stoi(dateEnd.substr(YEAR));
  27.  
  28.     while (++currentYear < lastYear) {
  29.         std::string currentStringYear = std::to_string(currentYear);
  30.         std::string currentStringOriginalYear = currentStringYear;
  31.         std::reverse(currentStringYear.begin(), currentStringYear.end());
  32.         std::string LastFourNumsInTheYear = currentStringYear.substr(currentStringYear.length() - 4);
  33.         std::string stringDay = LastFourNumsInTheYear.substr(0, 2);
  34.         std::string stringMonth = LastFourNumsInTheYear.substr(2,2);
  35.  
  36.         int intDay = std::stoi(stringDay);
  37.         int intMonth = std::stoi(stringMonth);
  38.  
  39.         if (intMonth == 2) {
  40.             if (!((isleap(std::stoi(currentStringOriginalYear)) && intDay < 30) || (!isleap(std::stoi(currentStringOriginalYear)) && intDay < 29))) {
  41.                 continue;
  42.             }
  43.         }
  44.         if ((0 < intDay && intDay <= (31 - (intMonth - 1) % 7 % 2)) && (0 < intMonth && intMonth < 13)) {
  45.             std::string potincailPolindrome = createDate(currentStringOriginalYear, stringMonth, stringDay);
  46.             if (isPolindrome(potincailPolindrome)) {
  47.                 std::string datePolindrome = createOutputPolindromes(potincailPolindrome);
  48.                 Polindromes.push_back(datePolindrome);
  49.             }
  50.         }
  51.     }
  52.  
  53.  
  54.  
  55.  
  56.     return Polindromes;
  57. }
  58.  
  59.  
  60.  
  61.  
  62.  
  63. int main(){
  64.     for (std::string str : datePolindrom("06.22.1000", "06.22.2261")) {
  65.         std::cout << str << "\n";
  66.      }
  67.     return 1;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement