-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek_12.txt
99 lines (95 loc) · 3.03 KB
/
week_12.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
resource url?
QUESTION ----------------
Background:
------------------ANSWER
total=int(input())
sizes=list(map(int, input().split()))
inventory={}
for size in sizes:
inventory[size] = inventory.get(size, 0) + 1
requests=int(input())
total_revenue = 0
for _ in range(requests):
requested_size, price = map(int, input().split())
if inventory.get(requested_size, 0) > 0:
total_revenue += price
inventory[requested_size] -= 1
print(total_revenue)
------------------------------
QUESTION ----------------
Background:
------------------ANSWER
import csv
import sys
def calculate_average_marks(input_data):
reader = csv.DictReader(input_data, delimiter=' ')
total_marks = 0
student_count = 0
for row in reader:
total_marks += int(row['MARKS'])
student_count += 1
average_marks = total_marks / student_count if student_count else 0
print(f"{average_marks:.2f}")
if __name__ == "__main__":
input_data = sys.stdin.read().splitlines()
n = int(input_data[0])
column_headers = input_data[1]
student_data = input_data[2:n+2]
input_csv = [column_headers] + student_data
calculate_average_marks(input_csv)
------------------------------
QUESTION ----------------
Given an integer n, print true if it is a power of four. Otherwise, print false.
------------------ANSWER
import math
N=int(input())
flag=0
for i in range(0,N):
if math.pow(4,i)==N:
flag=1
break
if flag==0:
print("False")
else:
print("True")
------------------------------
QUESTION ----------------
As a software engineer at SocialLink, a leading social networking application, you are tasked with developing a new feature designed to enhance user interaction and engagement. The company aims to introduce a system where users can form connections based on shared interests and activities. One of the feature's components involves analyzing pairs of users based on the activities they've participated in, specifically looking at the numerical difference in the number of activities each user has participated in.
------------------ANSWER
n = int(input())
nums = list(map(int, input().split()))
k = int(input())
if k == 0:
freq_map = {}
count = 0
for num in nums:
freq_map[num] = freq_map.get(num, 0) + 1
for num in freq_map:
count += freq_map[num] * (freq_map[num] - 1) // 2
print(count)
exit()
freq_map = {}
count = 0
for num in nums:
freq_map[num] = freq_map.get(num, 0) + 1
for num in nums:
if num - k in freq_map:
count += freq_map[num - k]
print(count)
------------------------------
QUESTION ----------------
Background:
------------------ANSWER
from collections import defaultdict as d
mapping = d(lambda : [])
while True:
try:
string = input()
except EOFError:
break
else:
row = list(map(str.strip, string.split(',')))
mapping[row[1]] += [row[0]]
for (k,v) in mapping.items():
print(f"{k}: {', '.join(v)}")
------------------------------