Advertisement
asdfg0998

dwewd

Nov 15th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1.  int monthCount[12] = {0}; // Array to store counts for months (0: "01", 11: "12")
  2.  
  3.     // Count occurrences of each month
  4.     for (const std::string& date : dateList) {
  5.         int month = (date[5] - '0') * 10 + (date[6] - '0') - 1; // Extract month as an integer (0-based index)
  6.         monthCount[month]++;
  7.     }
  8.  
  9.     // Find the month with the highest count
  10.     int maxCount = 0;
  11.     int resultMonth = 0;
  12.  
  13.     for (int i = 0; i < 12; ++i) {
  14.         if (monthCount[i] > maxCount || (monthCount[i] == maxCount && i > resultMonth)) {
  15.             maxCount = monthCount[i];
  16.             resultMonth = i;
  17.         }
  18.     }
  19.  
  20.     // Convert the resultMonth back to a two-digit string
  21.     char result[3];
  22.     std::sprintf(result, "%02d", resultMonth + 1);
  23.     return std::string(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement