Skip to content

Commit c6455f7

Browse files
committed
Day 24 is partially updated. Need more make up.
1 parent 5cde733 commit c6455f7

File tree

1 file changed

+64
-134
lines changed

1 file changed

+64
-134
lines changed

Status/Day_24.md

Lines changed: 64 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -2,219 +2,149 @@
22

33
### **Question**
44

5-
>***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.***
5+
>***You are given words. Some words may repeat. For each word, output its number of occurrences. The output order should correspond with the input order of appearance of the word. See the sample input/output for clarification.***
66
77
>***If the following string is given as input to the program:***
88
>```
9-
>5
10-
>2 3 6 6 5
9+
>4
10+
>bcdef
11+
>abcdefg
12+
>bcde
13+
>bcdef
1114
>```
1215
>***Then, the output of the program should be:***
1316
>```
14-
>5
17+
>3
18+
>2 1 1
1519
>```
20+
1621
### Hints
17-
> ***Make the scores unique and then find 2nd best number***
22+
> ***Make a list to get the input order and a dictionary to count the word frequency***
1823
1924
----------------------
2025
**My Solution: Python 3**
2126
```python
2227
n = int(input())
23-
arr = map(int, input().split())
24-
arr = list(set(arr))
25-
arr.sort()
26-
print(arr[-2])
28+
29+
word_list = []
30+
word_dict = {}
31+
32+
for i in range(n):
33+
word = input()
34+
if word not in word_dict:
35+
word_list.append(word)
36+
word_dict[word] = word_dict.get(word, 0) + 1
37+
38+
print(len(word_list))
39+
for word in word_list:
40+
print(word_dict[word], end=' ')
2741
```
2842
---------------------
2943

30-
# Question 96
44+
# Question 101
3145

3246
### **Question**
3347

34-
>***You are given a string S and width W.
35-
Your task is to wrap the string into a paragraph of width.***
48+
>***You are given a string.Your task is to count the frequency of letters of the string and print the letters in descending order of frequency.***
3649
3750
>***If the following string is given as input to the program:***
3851
>```
39-
>ABCDEFGHIJKLIMNOQRSTUVWXYZ
40-
>4
52+
>aabbbccde
4153
>```
4254
>***Then, the output of the program should be:***
4355
>```
44-
>ABCD
45-
>EFGH
46-
>IJKL
47-
>IMNO
48-
>QRST
49-
>UVWX
50-
>YZ
56+
>b 3
57+
>a 2
58+
>c 2
5159
>```
5260
5361
### Hints
54-
> ***Use wrap function of textwrap module***
62+
> ***Count frequency with dictionary and sort by Value from dictionary Items***
5563
5664
----------------------
5765
5866
**My Solution: Python 3**
5967
```python
60-
import textwrap
61-
62-
def wrap(string, max_width):
63-
string = textwrap.wrap(string,max_width)
64-
string = "\n".join(string)
65-
return string
66-
67-
if __name__ == '__main__':
68-
string, max_width = input(), int(input())
69-
result = wrap(string, max_width)
70-
print(result)
68+
word = input()
69+
dct = {}
70+
for i in word:
71+
dct[i] = dct.get(i,0) + 1
72+
73+
dct = sorted(dct.items(),key=lambda x: (-x[1],x[0]))
74+
for i in dct[:3]:
75+
print(i[0],i[1])
7176
```
7277
---------------------
7378

74-
# Question 97
7579

80+
# Question 102
7681
### **Question**
7782

78-
>***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.)***
79-
80-
>***Different sizes of alphabet rangoli are shown below:***
81-
>```
82-
>#size 3
83-
>
84-
>----c----
85-
>--c-b-c--
86-
>c-b-a-b-c
87-
>--c-b-c--
88-
>----c----
89-
>
90-
>#size 5
91-
>
92-
>--------e--------
93-
>------e-d-e------
94-
>----e-d-c-d-e----
95-
>--e-d-c-b-c-d-e--
96-
>e-d-c-b-a-b-c-d-e
97-
>--e-d-c-b-c-d-e--
98-
>----e-d-c-d-e----
99-
>------e-d-e------
100-
>--------e--------
101-
>```
102-
### Hints
103-
>***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.***
104-
105-
----------------------
106-
**My Solution: Python 3**
107-
```python
108-
109-
import string
110-
def print_rangoli(size):
111-
n = size
112-
alph = string.ascii_lowercase
113-
width = 4 * n - 3
114-
115-
ans = []
116-
for i in range(n):
117-
left = '-'.join(alph[n - i - 1:n])
118-
mid = left[-1:0:-1] + left
119-
final = mid.center(width, '-')
120-
ans.append(final)
121-
122-
if len(ans) > 1:
123-
for i in ans[n - 2::-1]:
124-
ans.append(i)
125-
ans = '\n'.join(ans)
126-
print(ans)
127-
128-
129-
if __name__ == '__main__':
130-
n = int(input())
131-
print_rangoli(n)
132-
```
133-
---------------------
134-
135-
136-
# Question 98
137-
138-
### **Question**
139-
140-
>***You are given a date. Your task is to find what the day is on that date.***
83+
>***Write a Python program that accepts a string and calculate the number of digits and letters.***
14184
14285
**Input**
143-
>***A single line of input containing the space separated month, day and year, respectively, in MM DD YYYY format.***
14486
>```
145-
>08 05 2015
87+
>Hello321Bye360
14688
>```
14789
148-
14990
**Output**
150-
>***Output the correct day in capital letters.***
15191
>```
152-
>WEDNESDAY
92+
>Digit - 6
93+
>Letter - 8
15394
>```
154-
155-
15695
----------------------
15796
### Hints
158-
> ***Use weekday function of calender module***
97+
> ***Use isdigit() and isalpha() function***
15998
16099
----------------------
161100
162101
**Solution:**
163102
```python
164-
import calendar
165-
166-
month, day, year = map(int, input().split())
167-
168-
dayId = calendar.weekday(year, month, day)
169-
print(calendar.day_name[dayId].upper())
103+
word = input()
104+
digit,letter = 0,0
105+
for char in word:
106+
digit+=char.isdigit()
107+
letter+=char.isalpha()
108+
109+
print('Digit -',digit)
110+
print('Letter -',letter)
170111
```
171112
----------------
172113

173114

174-
# Question 99
115+
# Question 103
175116

176117
### **Question**
177118

178-
>***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.***
119+
>***Given a number N.Find Sum of 1 to N Using Recursion***
179120
180121
**Input**
181-
>***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.***
182122
>```
183-
>4
184-
>2 4 5 9
185-
>4
186-
>2 4 11 12
123+
>5
187124
>```
188125
189126
**Output**
190-
>***Output the symmetric difference integers in ascending order, one per line.***
191127
>```
192-
>5
193-
>9
194-
>11
195-
>12
128+
>15
196129
>```
197130
198-
199131
----------------------
200132
### Hints
201-
> ***Use \'^\' to make symmetric difference operation.***
133+
> ***Make a recursive function to get the sum***
202134
203135
----------------------
204136
205137
**Solution:**
206138
```python
207-
if __name__ == '__main__':
208-
n = int(input())
209-
set1 = set(map(int,input().split()))
139+
def rec(n):
140+
if n == 0:
141+
return n
142+
return rec(n-1) + n
210143
211-
m = int(input())
212-
set2 = set(map(int, input().split()))
213144
214-
ans = list(set1 ^ set2)
215-
ans.sort()
216-
for i in ans:
217-
print(i)
145+
n = int(input())
146+
sum = rec(n)
147+
print(sum)
218148
```
219149
----------------
220150

0 commit comments

Comments
 (0)