avr39ripe

cppHourSymmetry

Jun 28th, 2021
608
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. //00:00
  4. //01:10
  5. //21:12
  6. //02:20
  7. //22:22
  8. //11:11
  9. //
  10. //
  11. //23:54
  12. //12:41
  13.  
  14. int main()
  15. {
  16.     const int maxHour{ 24 };
  17.     const int maxMinute{ 60 };
  18.     int hourHigh;
  19.     int hourLow;
  20.     int minuteHigh;
  21.     int minuteLow;
  22.     //int reverseMinute;
  23.     int count{ 0 };
  24.  
  25.     for (int hour{ 0 }; hour < maxHour; ++hour)
  26.     {
  27.         hourLow = hour % 10;
  28.         hourHigh = hour / 10;
  29.  
  30.         for (int minute{ 0 }; minute < maxMinute; ++minute)
  31.         {
  32.             minuteLow = minute % 10;
  33.             minuteHigh = minute / 10;
  34.             //reverseMinute = minuteLow * 10 + minuteHigh;
  35.  
  36.             if ((hourHigh == minuteLow) and (hourLow == minuteHigh))
  37.             //if ( hour == reverseMinute)
  38.             {
  39.                 ++count;
  40.                 std::cout << hourHigh << hourLow << ':' << minuteHigh << minuteLow << '\n';
  41.             }
  42.         }
  43.     }
  44.  
  45.     std::cout << "Total symmetric values: " << count << '\n';
  46.     return 0;
  47. }
RAW Paste Data