Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int monthCount[12] = {0}; // Array to store counts for months (0: "01", 11: "12")
- // Count occurrences of each month
- for (const std::string& date : dateList) {
- int month = (date[5] - '0') * 10 + (date[6] - '0') - 1; // Extract month as an integer (0-based index)
- monthCount[month]++;
- }
- // Find the month with the highest count
- int maxCount = 0;
- int resultMonth = 0;
- for (int i = 0; i < 12; ++i) {
- if (monthCount[i] > maxCount || (monthCount[i] == maxCount && i > resultMonth)) {
- maxCount = monthCount[i];
- resultMonth = i;
- }
- }
- // Convert the resultMonth back to a two-digit string
- char result[3];
- std::sprintf(result, "%02d", resultMonth + 1);
- return std::string(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement