Skip to content
🤔prompts chat🧠
🔍
question:A company wants to keep track of their employees' working hours by logging the check-in and check-out times. You need to determine the total worked hours for each employee over a given period. -----Input----- The first line contains integer m (1 ≤ m ≤ 10^3) — the number of employees. Each of the following m lines contains: - An integer e (1 ≤ e ≤ 10^5) — the employee ID. - A string t (format "YYYY-MM-DD HH:MM:SS") indicating the timestamp. - A string s ("check-in" or "check-out") indicating the event type. -----Output----- Print m lines: each of them must contain the employee ID followed by the total worked hours (rounded to two decimal places) for that employee. -----Examples----- Input: 3 1 2023-01-01 08:00:00 check-in 1 2023-01-01 16:00:00 check-out 2 2023-01-01 09:30:00 check-in 2 2023-01-01 17:45:00 check-out 3 2023-01-01 10:15:00 check-in 3 2023-01-01 18:30:00 check-out Output: 1 8.00 2 8.25 3 8.25

answer:from datetime import datetime def calculate_worked_hours(logs): work_log = {} work_hours = {} for entry in logs: employee_id, timestamp, event = entry timestamp = datetime.strptime(timestamp, "%Y-%m-%d %H:%M:%S") if event == "check-in": work_log[employee_id] = timestamp elif event == "check-out": if employee_id in work_log: check_in_time = work_log.pop(employee_id) worked_time = (timestamp - check_in_time).total_seconds() / 3600.0 if employee_id in work_hours: work_hours[employee_id] += worked_time else: work_hours[employee_id] = worked_time result = [] for employee_id in sorted(work_hours.keys()): result.append(f"{employee_id} {work_hours[employee_id]:.2f}") return result # Parsing input def main(): import sys input = sys.stdin.read data = input().strip().split('n') m = int(data[0]) logs = [] for i in range(1, m + 1): parts = data[i].split() employee_id = int(parts[0]) timestamp = parts[1] + " " + parts[2] event = parts[3] logs.append((employee_id, timestamp, event)) result = calculate_worked_hours(logs) for line in result: print(line)

question:You are given a matrix consisting of `n` rows and `m` columns, where each cell either contains a `1` or a `0`. The matrix represents a grid where cells with `1` are considered obstacles, and cells with `0` are traversable. Your task is to determine the size of the largest square (subgrid) that can be formed using only traversable cells (`0`s). Write a function `largestSquare(matrix)` that takes a matrix as input and returns an integer indicating the size (side length) of the largest square consisting entirely of `0`s. -----Input----- - The first line contains two integers `n` and `m` (1 le n, m le 1000), representing the number of rows and columns in the matrix, respectively. - The next `n` lines each contain `m` integers `0` or `1`, representing the cells of the matrix. -----Output----- - Output a single integer, which is the side length of the largest square consisting only of `0`s. -----Examples----- Sample Input 1: 4 5 1 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 1 1 1 0 Sample Output 1: 2 Sample Input 2: 3 3 0 0 0 0 0 0 0 0 0 Sample Output 2: 3

answer:def largestSquare(matrix): if not matrix or not matrix[0]: return 0 n = len(matrix) m = len(matrix[0]) dp = [[0] * m for _ in range(n)] max_side = 0 for i in range(n): for j in range(m): if matrix[i][j] == 0: if i == 0 or j == 0: dp[i][j] = 1 else: dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) + 1 max_side = max(max_side, dp[i][j]) return max_side

question:Bob is training for a marathon and wants to track his daily running distances over a period of days. Each day, he either runs a specific number of kilometers or takes a rest day (runs 0 kilometers). He wants to find out the maximum distance he has run on any single day during this period. Help Bob determine the maximum distance run in a single day. ------ Input Format ------ The first line contains an integer T denoting the number of test cases. Each test case consists of: - The first line contains an integer D, the number of days. - The second line contains D space-separated integers where each integer denotes the distance run on a specific day. A value of 0 indicates a rest day. ------ Output Format ------ For each test case, print a single integer, the maximum distance run on any single day. ------ Constraints ------ 1 ≤ T ≤ 100 1 ≤ D ≤ 365 0 ≤ text{distance} ≤ 100 ----- Sample Input 1 ------ 2 3 5 0 10 4 0 0 0 0 ----- Sample Output 1 ------ 10 0 ----- Explanation 1 ------ In the first test case, Bob ran 5 kilometers on the first day, 0 kilometers on the second day, and 10 kilometers on the third day. The maximum distance run on any single day is 10 kilometers. In the second test case, Bob took a rest every day, so the maximum distance run on any single day is 0 kilometers.

answer:def max_distance_per_day(test_cases): Given the number of test cases, and for each test case, the number of days and the distances run each day, this function returns a list of maximum distances run on any single day for each test case. results = [] for case in test_cases: days, distances = case results.append(max(distances)) return results # Example usage # test_cases = [ # (3, [5, 0, 10]), # (4, [0, 0, 0, 0]) # ] # print(max_distance_per_day(test_cases)) # Output: [10, 0]

question:Task Given a string, s, perform the following actions: If s contains the substring "hello", print Present If s contains the substring "world" but does not contain "hello", print Absent If s contains neither "hello" nor "world", print Not Found Input Format A single line containing a string, s. Constraints 1 leq text{length of } s leq 100 Output Format Print Present if the string contains "hello". If the string does not contain "hello" but contains "world", print Absent. If the string contains neither, print Not Found. Sample Input 0 hellothere Sample Output 0 Present Explanation 0 s=hellothere s contains the substring "hello", so print Present. Sample Input 1 worldofcode Sample Output 1 Absent Explanation 1 s=worldofcode s contains the substring "world" but not "hello", so print Absent. Sample Input 2 codingisfun Sample Output 2 Not Found Explanation 2 s=codingisfun s contains neither "hello" nor "world", so print Not Found.

answer:def check_string(s): Prints "Present" if the string contains "hello". Prints "Absent" if the string contains "world" but does not contain "hello". Prints "Not Found" if the string contains neither "hello" nor "world". if "hello" in s: print("Present") elif "world" in s: print("Absent") else: print("Not Found")

Released under the chat License.

has loaded