File tree 2 files changed +92
-0
lines changed 2 files changed +92
-0
lines changed Original file line number Diff line number Diff line change
1
+ '''Given an array arr of N integers
2
+ write a function that
3
+ returns true if there is a triplet (a, b, c)
4
+ that satisfies a2 + b2 = c2
5
+ otherwise false'''
6
+
7
+ import math
8
+
9
+ def checkTriplet (arr , n ):
10
+ mxm = 0
11
+
12
+ # finding maximum element
13
+ for element in arr :
14
+ mxm = max (mxm , element )
15
+
16
+ # hashing array
17
+ hash = [0 ]* (mxm + 1 )
18
+
19
+ for element in arr :
20
+ hash [element ] += 1
21
+
22
+ for i in range (1 , mxm + 1 ):
23
+ if hash [i ] == 0 :
24
+ continue
25
+
26
+ for j in range (1 , mxm + 1 ):
27
+ if (i == j and hash [i ]== 1 ) or hash [j ]== 0 :
28
+ continue
29
+
30
+ val = int (math .sqrt (i * i + j * j ))
31
+ if val * val != (i * i + j * j ):
32
+ continue
33
+ if val > mxm :
34
+ continue
35
+ if hash [val ]:
36
+ return True
37
+ return False
38
+
39
+ '''n = int(input())
40
+ a = list(map(int,input().split()))'''
41
+
42
+ N = 5
43
+ Arr = [3 , 2 , 4 , 6 , 5 ]
44
+
45
+ # N = 3
46
+ # Arr = [3, 8, 5]
47
+
48
+ if checkTriplet (Arr , N ):
49
+ print ("Yes" )
50
+ else :
51
+ print ("No" )
Original file line number Diff line number Diff line change
1
+ '''
2
+ Input:
3
+ The first line of each test case contains the no of test cases T
4
+ Then T test cases follow. Each test case contains a string s denoting the roman no
5
+
6
+ Output:
7
+ For each test case in a new line print the integer representation of roman number s
8
+ '''
9
+
10
+ def roman_to_int (roman ):
11
+ value = {
12
+ 'I' : 1 ,
13
+ 'V' : 5 ,
14
+ 'X' : 10 ,
15
+ 'L' : 50 ,
16
+ 'C' : 100 ,
17
+ 'D' : 500 ,
18
+ 'M' : 1000
19
+ }
20
+
21
+ prev = 0
22
+ ans = 0
23
+ n = len (roman )
24
+ for i in range (n - 1 , - 1 , - 1 ):
25
+ if value [roman [i ]] >= prev :
26
+ ans += value [roman [i ]]
27
+ else :
28
+ ans -= value [roman [i ]]
29
+
30
+ prev = value [roman [i ]]
31
+
32
+ print (ans )
33
+ '''for _ in range(int(input())):
34
+ s = input()
35
+ roman_to_int(s)
36
+ '''
37
+ # s = 'V'
38
+ # s = 'III'
39
+ s = 'XIV'
40
+
41
+ roman_to_int (s )
You can’t perform that action at this time.
0 commit comments