-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDay_23.py
304 lines (245 loc) · 4.91 KB
/
Day_23.py
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#!/usr/bin/env python
# coding: utf-8
# # The extended part of the repository starts from this page. Previous 94 problems were collected from the repository mentioned in intro. The following problems are collected from Hackerrank and other resources from internet.
#
# # Question 95
#
# ### **Question**
#
# > **_Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given scores. Store them in a list and find the score of the runner-up._**
#
# > **_If the following string is given as input to the program:_**
# >
# > 5
# > 2 3 6 6 5
# >
# > **_Then, the output of the program should be:_**
# >
# > 5
#
# ### Hints
#
# > **_Make the scores unique and then find 2nd best number_**
#
# ---
#
# **Solutions:**
# In[1]:
arr = map(int, input().split())
arr = list(set(arr))
arr.sort()
print(arr[-2])
# ---
# In[2]:
"""
Solution by: mishrasunny-coder
"""
num = int(input("Enter num: "))
L = []
while True:
L.append(num)
num = int(input("Enter another: "))
if num == 0:
break
L1 = list(set(L[:]))
L2 = sorted(L1)
print(L2)
print(f"The runner up is {L2[-2]}")
# ---
#
# # Question 96
#
# ### **Question**
#
# > **_You are given a string S and width W.
# > Your task is to wrap the string into a paragraph of width._**
#
# > **_If the following string is given as input to the program:_**
# >
# > ABCDEFGHIJKLIMNOQRSTUVWXYZ
# > 4
# >
# > **_Then, the output of the program should be:_**
# >
# > ABCD
# > EFGH
# > IJKL
# > IMNO
# > QRST
# > UVWX
# > YZ
#
# ### Hints
#
# > **_Use wrap function of textwrap module_**
#
# ---
#
# **Solutions:**
# In[3]:
import textwrap
def wrap(string, max_width):
string = textwrap.wrap(string, max_width)
string = "\n".join(string)
return string
if __name__ == "__main__":
string, max_width = input(), int(input())
result = wrap(string, max_width)
print(result)
# ---
# In[ ]:
"""
Solution by: mishrasunny-coder
"""
import textwrap
string = input()
width = int(input())
print(textwrap.fill(string, width))
# ---
#
# # Question 97
#
# ### **Question**
#
# > **_You are given an integer, N. Your task is to print an alphabet rangoli of size N. (Rangoli is a form of Indian folk art based on creation of patterns.)_**
#
# > **_Different sizes of alphabet rangoli are shown below:_**
# >
# > $size = 3$
# >
# > ----c----
#
# > --c-b-c--
#
# > c-b-a-b-c
#
# > --c-b-c--
#
# > ----c----
# >
# > $size = 5$
# >
# > --------e--------
#
# > ------e-d-e------
#
# > ----e-d-c-d-e----
#
# > --e-d-c-b-c-d-e--
#
# > e-d-c-b-a-b-c-d-e
#
# > --e-d-c-b-c-d-e--
#
# > ----e-d-c-d-e----
#
# > ------e-d-e------
#
# > --------e--------
#
# ### Hints
#
# > **_First print the half of the Rangoli in the given way and save each line in a list. Then print the list in reverse order to get the rest._**
#
# ---
#
# **Solutions:**
# In[ ]:
import string
def print_rangoli(size):
n = size
alph = string.ascii_lowercase
width = 4 * n - 3
ans = []
for i in range(n):
left = "-".join(alph[n - i - 1 : n])
mid = left[-1:0:-1] + left
final = mid.center(width, "-")
ans.append(final)
if len(ans) > 1:
for i in ans[n - 2 :: -1]:
ans.append(i)
ans = "\n".join(ans)
print(ans)
if __name__ == "__main__":
n = int(input())
print_rangoli(n)
# ---
#
# # Question 98
#
# ### **Question**
#
# > **_You are given a date. Your task is to find what the day is on that date._**
#
# **Input**
#
# > **_A single line of input containing the space separated month, day and year, respectively, in MM DD YYYY format._**
# >
# > 08 05 2015
#
# **Output**
#
# > **_Output the correct day in capital letters._**
# >
# > WEDNESDAY
#
# ---
#
# ### Hints
#
# > **_Use weekday function of calender module_**
#
# ---
#
# **Solution:**
# In[ ]:
import calendar
month, day, year = map(int, input().split())
dayId = calendar.weekday(year, month, day)
print(calendar.day_name[dayId].upper())
# ---
#
# # Question 99
#
# ### **Question**
#
# > **_Given 2 sets of integers, M and N, print their symmetric difference in ascending order. The term symmetric difference indicates those values that exist in either M or N but do not exist in both._**
#
# **Input**
#
# > **_The first line of input contains an integer, M.The second line contains M space-separated integers.The third line contains an integer, N.The fourth line contains N space-separated integers._**
# >
# > 4
# > 2 4 5 9
# > 4
# > 2 4 11 12
#
# **Output**
#
# > **_Output the symmetric difference integers in ascending order, one per line._**
# >
# > 5
# > 9
# > 11
# > 12
#
# ---
#
# ### Hints
#
# > **_Use \'^\' to make symmetric difference operation._**
#
# ---
#
# **Solution:**
# In[ ]:
n = int(input())
set1 = set(map(int, input().split()))
m = int(input())
set2 = set(map(int, input().split()))
ans = list(set1 ^ set2)
ans.sort()
for i in ans:
print(i)
# In[ ]: