SHARE
TWEET

Untitled

a guest Feb 19th, 2020 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. #define YEAR 6
  6. #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
  7.  
  8. int Dispersion(std::vector<int> vec) {
  9.     int meanVec = 0; // Среднее значение чисел вектора
  10.     int sum = 0; // сумма всех элементов массива
  11.     int dispNum = 0; // Дисперсия
  12.  
  13.     for (int i : vec) {
  14.         sum += i;
  15.     }
  16.    
  17.     meanVec = sum / vec.size();
  18.    
  19.     for (int i : vec) {
  20.         dispNum += ((i - meanVec) * (i - meanVec)) / vec.size();
  21.        
  22.     }
  23.  
  24.     return dispNum;
  25. }
  26.  
  27.  
  28. double closeNum(std::vector<double> vec, double R) {
  29.     double min = abs(vec.at(0) - R);
  30.     double output = 0.0;
  31.  
  32.     for (double x : vec) {
  33.         if (abs(x - R) <= min) {
  34.             min = abs(x - R);
  35.             output = x;
  36.         }
  37.     }
  38.     return output;
  39. }
  40.  
  41.  
  42. std::vector<int> EqNums(std::vector<int> vec) {
  43.     std::vector<int> mas1;
  44.     std::vector<int> mas2;
  45.     std::vector<int> mas3;
  46.  
  47.     int prev = vec[0];
  48.     int  counter = 0;
  49.  
  50.     for (int i = 0; i < vec.size(); i++) {
  51.         if (prev != vec[i]) {
  52.             counter = 0;
  53.             prev = vec[i];
  54.         }
  55.         mas2.push_back(counter++);
  56.     }
  57.  
  58.     counter = 0;
  59.     prev = vec[vec.size()-1];
  60.     for (int i = vec.size()-1; i >= 0; --i) {
  61.         if (prev != vec[i]) {
  62.             counter = 0;
  63.             prev = vec[i];
  64.         }
  65.         mas1.push_back(counter++);
  66.     }
  67.  
  68.     std::reverse(std::begin(mas1), std::end(mas1));
  69.  
  70.     for (int i = 0; i < mas2.size(); i++) {
  71.         mas3.push_back(mas1[i] > mas2[i] ? mas2[i] : mas1[i]);
  72.     }
  73.  
  74.     return mas3;
  75. }
  76.  
  77.  
  78. bool isPolindrome(std::string str) {
  79.     return str == std::string(str.rbegin(), str.rend());
  80. }
  81.  
  82.  
  83. std::string createOutputPolindromes(std::string date) {
  84.     return date.substr(0, 2) + "." + date.substr(2, 2) + "." + date.substr(4);
  85. }
  86.  
  87. std::string createDate(const std::string& year, const std::string& month, const std::string& day) {
  88.     return day + month + year;
  89. }
  90.  
  91.  
  92. std::vector<std::string> datePolindrom(std::string dateStart, std::string dateEnd) {
  93.     std::vector<std::string> Polindromes;
  94.  
  95.  
  96.     int currentYear = std::stoi(dateStart.substr(YEAR)) - 1;
  97.     int lastYear = std::stoi(dateEnd.substr(YEAR));
  98.  
  99.     while (++currentYear < lastYear) {
  100.         std::string currentStringYear = std::to_string(currentYear);
  101.         std::string currentStringOriginalYear = currentStringYear;
  102.         std::reverse(currentStringYear.begin(), currentStringYear.end());
  103.         std::string LastFourNumsInTheYear = currentStringYear.substr(currentStringYear.length() - 4);
  104.         std::string stringDay = LastFourNumsInTheYear.substr(0, 2);
  105.         std::string stringMonth = LastFourNumsInTheYear.substr(2,2);
  106.  
  107.         int intDay = std::stoi(stringDay);
  108.         int intMonth = std::stoi(stringMonth);
  109.  
  110.         if (intMonth == 2) {
  111.             if (!((isleap(std::stoi(currentStringOriginalYear)) && intDay < 30) || (!isleap(std::stoi(currentStringOriginalYear)) && intDay < 29))) {
  112.                 continue;
  113.             }
  114.         }
  115.         if ((0 < intDay && intDay <= (31 - (intMonth - 1) % 7 % 2)) && (0 < intMonth && intMonth < 13)) {
  116.             std::string potincailPolindrome = createDate(currentStringOriginalYear, stringMonth, stringDay);
  117.             std::string potentialPalindromeReversed = createDate(currentStringYear, stringMonth, stringDay);
  118.             if (isPolindrome(potincailPolindrome)) {
  119.                 std::string datePolindrome = createOutputPolindromes(potincailPolindrome);
  120.                 Polindromes.push_back(datePolindrome);
  121.             }
  122.             else if (potincailPolindrome != potentialPalindromeReversed && isPolindrome(potentialPalindromeReversed)) {
  123.                 std::string datePolindrome = createOutputPolindromes(potincailPolindrome);
  124.                 Polindromes.push_back(datePolindrome);
  125.             }
  126.         }
  127.     }
  128.     return Polindromes;
  129. }
  130.  
  131.  
  132.  
  133.  
  134.  
  135. int main(){
  136.     for (std::string str : datePolindrom("06.22.1000", "06.22.2261")) {
  137.         std::cout << str << "\n";
  138.      }
  139.     return 1;
  140. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top