Skip Lunch Count
Count the number of days an employee skips lunch based on breakfast timing after 11:00 AM
Understand the Problem
Problem Statement
An employee skips lunch on a given day if he has breakfast after 11:00 AM. Given the breakfast times for N days in 24-hour format, determine how many days the employee skipped lunch.
Constraints
- 1 ≤ N ≤ 100
- Breakfast time is given in HH:MM 24-hour format
- Time values are valid (HH from 00-23, MM from 00-59)
- Each day's breakfast time is separated by a space
Examples
5
10:00 11:00 11:01 9:00 11:052The employee had breakfast after 11:00 AM on the 3rd day (11:01) and 5th day (11:05), so he skipped lunch on 2 days. Breakfast at exactly 11:00 AM (2nd day) does not count as after 11:00 AM.
Solution
#include <stdio.h>
#include <string.h>
int main() {
int n;
scanf("%d", &n);
int skipCount = 0;
char time[6];
for(int i = 0; i < n; i++) {
scanf("%s", time);
// Parse hour and minute
int hour = (time[0] - '0') * 10 + (time[1] - '0');
int minute = (time[3] - '0') * 10 + (time[4] - '0');
// Check if breakfast was after 11:00 AM
if(hour > 11 || (hour == 11 && minute > 0)) {
skipCount++;
}
}
printf("%d", skipCount);
return 0;
}1. Read the number of days N
2. For each day, read the breakfast time as a string
3. Parse the hour (first two characters) and minute (characters 4-5) from the time string
4. Check if hour > 11 OR (hour == 11 AND minute > 0)
5. Increment counter for each day breakfast was after 11:00 AM
6. Print the final count