-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuvi_debugger_python.py
211 lines (180 loc) · 4.54 KB
/
Guvi_debugger_python.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
''' string manipulation
In a school there are voting to choose the monitor of class.
#Your task is to tell which candidate is winner and if there is a tie print the name of candidate whose come first in lexicographical order.
Input Description:-
You are given with the space separated names.
Output Description:-
Print the winner’s name and the votes he earned.
Sample Input :
john johnny jackie johnny john jackie jamie jamie john johnny jamie johnny john
Sample Output :
john 4.'''
from collections import defaultdict
mylist = list(input().split())
mydict = defaultdict(int)
for i in mylist:
if i not in mylist:
mydict[i] = 1
else:
mydict[i] = mydict[i] + 1
anslist = []
for i in mydict:
anslist.append(mydict[i])
max_num = max(anslist)
numlist = []
for i in mydict:
if mydict[i]==max_num:
numlist.append(i)
numlist = sorted(numlist)
print(numlist[0],max_num)
'''
You are given a string ‘s’.Print all the duplicate characters of string.
Input Description:-
String ‘s; is given
Output Description:-
Print only duplicate character and -1 if no character is duplicate.
Sample Input :
abcddee
Sample Output :
d e '''
s = input()
L1, L2 = [], []
for c in s[:] : # loop for string
if c in L1 : # check string are already on string or not
L2.append(c) # if yes then append c in l2
else : # else part add on l1
L1.append(c)
if L2[::] :#simply print out
print(*L2,end='')
else :
print(-1,end='')
'''You are given some words all in lower case letters your task is to print them in sorted order.
Input Description:-
You are given a string ‘s’
Output Description:-
Print the string in sorted order
Sample Input :
virat kohli
Sample Output :
kohli virat'''
n=list(input().split())
t=sorted(n)
print(*t)
'''
Write a Program to Check if a Date is Valid and Print the Incremented Date Otherwise Invalid
Input Description:-
A single line input contains a three integer separated by space
Output Description:-
Print the incremented date.
Sample Input :
16 1 2020
Sample Output :
17 1 2020'''
date=input()
dd,mm,yy=map(int,date.split(' '))
dd=int(dd)
yy=int(yy)
if(mm==1 or mm==3 or mm==5 or mm==7 or mm==8 or mm==10 or mm==12):
max1=31
elif(mm==4 or mm==6 or mm==9 or mm==11):
max1=30
elif(yy%4==0 or yy%400==0):
max1=29
else:
max1=28
#increment of date
#last month to new year
print(max1)
if( dd==31 and mm==12 ):
dd=1
mm=1
yy=yy+1
print(dd,mm,yy)
elif(mm<1 or mm>12):
print("Invalid")
elif(dd<1 or dd>max1):
print("Invalid")
elif dd>1 and dd!=max1 or dd<max1 and max1!=dd:
dd=dd+1
print(dd,mm,yy)
elif dd==max1:
dd=1
mm=mm+1
print(dd,mm,yy)
'''Ramit is given a list of both positive and negative integers. He has to tell the maximum sum out of all subarrays in the given list. He got confused and requested help from you. Now it is your task to find the maximum sum out of all subarrays in the given list.
Input Description:-
You are given a number 'n'. Next line contains n space separated numbers.
Output Description:-
Print the max sum of sub array.
Sample Input :
5
1 2 3 -2 5
Sample Output :
9'''
size = int(input())
a = list(map(int,input().split()))
maxsubar = a[0]
curr_max = a[0]
for i in range(1,size-1):
curr_max = max(a[i], curr_max + a[i+1])
maxsubar = max(maxsubar,curr_max)
curr_max=maxsubar
print(maxsubar)
'''Generate a hollow half pyramid pattern using numbers.
Input Description:-
Given an integer R indicates number of rows.Where 1
Output Description:-
Print the hollow half pyramid pattern using numbers based on the given integer R.
Sample Input :
5
Sample Output :
1
12
1 3
1 4
12345'''
n = int(input())
a=[]
j = 0
q = ''
for i in range (1,n+1):
q = q + str(i)
if i == 1:
a.append(1)
elif 1<i<n:
s = str(1) + (" " * j)+ str(i)
a.append(s)
j = j+1
else:
a.append(q)
for i in a:
print(i)
'''
You are given a number ‘n’, Your task is to print the binary sequence of a number ranging from 1 to N.
Input Description:-
Single line contains an integer number ‘N’.
Output Description:-
Print the binary sequence of numbers.
Sample Input :
3
Sample Output :
1 10 11'''
def rev(a):
b=""
for i in a:
b=i+b
return b
def number_TO_binary(n):
a=""
while n!=0:
if n%2==0 :
a+=str(0)
if n%2==1:
a+=str(1)
n=n//2
return rev(a)
n = int(input())
ans = []
for i in range(1, n+1):
ans.append(number_TO_binary(i))
print(*ans)