Skip to content

Commit e03e870

Browse files
Add files via upload
1 parent 83dec7d commit e03e870

8 files changed

+144
-0
lines changed

Second Largest Num.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Enter your code here. Read input from STDIN. Print output to STDOUT
2+
N= input()
3+
L= raw_input().split()
4+
I=[]
5+
assert N>=2 and N<=10
6+
#print type(L[0])
7+
for i in L:
8+
I.append(int(i))
9+
I.sort()
10+
#print L
11+
largest=max(I)
12+
#print "Large=" + str(largest)
13+
count=I.count(largest)
14+
for i in range(count):
15+
I.remove(largest)
16+
print max(I)
17+
18+
19+
20+
21+
5
22+
-7 -7 -7 -7 -6

Sets Subset.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
for i in range(int(input())): #More than 4 lines will result in 0 score. Blank lines won't be counted.
2+
a = int(input()); A = set(input().split())
3+
b = int(input()); B = set(input().split())
4+
print (A.issubset(B))
5+
6+
7+

Sets Superset.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
A,N= set(input().split()) , int(input())
2+
ans=True
3+
for i in range(N):
4+
check= set(input().split())
5+
ans= (ans) and ( A.issuperset(check)) and len(A)> len(check)
6+
print (ans)

Snakes&Ladder.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Enter your code here. Read input from STDIN. Print output to STDOUT
2+
T=input()
3+
def gamePlay(dice,position,ladders,snakes):
4+
ladders.sort()
5+
snakes.sort()
6+
ladderLow=[ladders[i][0] for i in range(len(ladders))]
7+
snakesHead=[snakes[i][0] for i in range(len(snakes))]
8+
count=0
9+
while (position<=98):
10+
roll=max(dice)
11+
position+=roll
12+
if position in snakesHead and roll!=1:
13+
roll-=1
14+
if position in snakesHead and roll==1:
15+
position = snakes[snakesHead.index(position)][1]
16+
17+
18+
if position in ladderLow:
19+
position= ladders[ladderLow.index(position)][1]
20+
count+=1
21+
print snakesHead
22+
print ladderLow
23+
print "count ="+str(count)
24+
print "position="+str(position)
25+
print "position="+str(position)
26+
return count
27+
28+
for testCase in range(T):
29+
N=input()
30+
ladders=[raw_input().split() for n in range(N)]
31+
M=input()
32+
snakes=[raw_input().split() for m in range(M)]
33+
position=1
34+
dice=[1,2,3,4,5,6]
35+
#Select the higher number
36+
#Check if there's a snake head
37+
#if there's a snake head go for the next highest number
38+
#if there's no snake head go for another roll and make a count of the step.
39+
#if there's a ladder bottom in the position, change the position and make a count
40+
#make sure the position reaches till 98.
41+
#steps=0
42+
maxCount=gamePlay(dice,position,ladders,snakes)
43+
print maxCount
44+
45+
46+
47+
48+
49+
50+
51+
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Enter your code here. Read input from STDIN. Print output to STDOUT
2+
N, M =map(int, raw_input().split())
3+
sample= [ map(int, raw_input().split()) for i in range(N)]
4+
k=input()
5+
sample.sort(key=lambda x: x[k])
6+
for i in sample:
7+
print " ".join(map(str,i))
8+
9+

Stack.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Enter your code here. Read input from STDIN. Print output to STDOUT
2+
'''
3+
class Stack(object):
4+
def __init__(self):
5+
self.stack=[]
6+
7+
def push(self,element):
8+
self.stack.append(element)
9+
10+
11+
def pop(self):
12+
if len(self.stack)!=0:
13+
self.stack.remove(self.stack[0])
14+
15+
def maxElement(self):
16+
if len(self.stack)!=0:
17+
return max(self.stack)
18+
'''
19+
20+
N=input()
21+
s=[]
22+
for n in range(N):
23+
#S=Stack()
24+
#print S.stack
25+
op= raw_input().split()
26+
if op[0]=='1':
27+
print op[1]
28+
s.insert(0,op[1])
29+
if op[0]=='2':
30+
s.pop(s[0])
31+
if op[0]=='3':
32+
print max(s)
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
n = int(input())
2+
s = set(map(int, raw_input().split()))
3+
for i in range(int(raw_input())):
4+
eval('s.{0}({1})'.format(*raw_input().split()+['']))
5+
6+
print(sum(s))

sets.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
numOfEng= raw_input()
2+
rollOfEng=set(raw_input().split())
3+
numOfFre= raw_input()
4+
rollOfFre=set(raw_input().split())
5+
6+
total= numOfEng+numOfFre
7+
8+
studentsTakingPaper= list(rollOfEng.union(rollOfFre)) #converting set into list
9+
print len(studentsTakingPaper)
10+

0 commit comments

Comments
 (0)