-
Notifications
You must be signed in to change notification settings - Fork 0
/
python array.txt
114 lines (85 loc) · 2.14 KB
/
python array.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/python3
import sys
j =" "
n = int(input().strip())
arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]
for i in range(0,len(arr)):
j = j + str(arr[n-i-1]) +" "
print (j)
#!/bin/python3
import sys
def hourglass(i,j):
return (arr[i-1][j-1]+arr[i-1][j]+arr[i-1][j+1]+arr[i][j]+arr[i+1][j-1]+arr[i+1][j]+arr[i+1][j+1])
arr = []
sum = []
max=0
for arr_i in range(6):
arr_t = [int(arr_temp) for arr_temp in input().strip().split(' ')]
arr.append(arr_t)
#print (arr)
#print (arr[0][1])
for i in range(6):
for j in range(6):
if (i-1 > -1 and i+1 < 6):
if (j-1 > -1 and j+1 < 6):
k=hourglass(i,j)
if k > max:
max=k
print (max)
Dynamic array # not fixed
#!/bin/python3
import sys
temp = input()
N = int(temp.split()[0])
Q = int(temp.split()[1])
seqList = []
query = []
lastAns= int(0)
for query_i in range(Q):
query_t = [int(query_temp) for query_temp in input().strip().split(' ')]
query.append(query_t)
#print (N)
#print (Q)
#print (query)
for i in query:
if i[0] == 1:
pos = int((bool(i[1]) ^ bool(lastAns))%N)
seqList[pos].append(i[2])
if i[0] == 2:
pos = int((bool(i[1]) ^ bool(lastAns))%N)
lastAns=int(i[2])%len(i)
print (lastAns)
rotate an array by 'd' steps to left
def rotate(l,n):
return l[n:] + l[:n]
temp = input()
N = int(temp.split()[0])
d = int(temp.split()[1])
l = [int(arr_temp) for arr_temp in input().strip().split(' ')]
m=(rotate(l,d))
final =""
for i in range(N):
final = final + str(m[i])+" "
print (final)
print (l[d:])
#number of times a string occurs
import sys
n =int(input().strip())
strings = [] #list [] string ""
for i in range(n):
temp = input()
strings.append(temp)
test =int(input().strip())
sample = []
for i in range(test):
temp = input()
sample.append(temp)
#print (strings + sample)
num = 0
for i in sample:
for j in strings:
c = i in j
num = num + int(c)
print (num)
num = 0