File tree 5 files changed +159
-0
lines changed
5 files changed +159
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+
4
+ int main (void )
5
+ {
6
+ int n , max = 0 ;
7
+ int absdiff ;
8
+ int element [10 ];
9
+
10
+ scanf ("%d" , & n );
11
+ for (int i = 0 ;i < n ;i ++ ) scanf ("%d" , & element [i ]);
12
+ //Aditya Seth
13
+ for (int i = 0 ;i < n - 1 ;i ++ )
14
+ {
15
+ for (int j = i + 1 ;j < n ;j ++ )
16
+ {
17
+ absdiff = abs (element [i ] - element [j ]);
18
+ if (max < absdiff ) max = absdiff ;
19
+ }
20
+ }
21
+ printf ("%d" , max );
22
+ }
Original file line number Diff line number Diff line change
1
+ #include < cmath>
2
+ #include < iostream>
3
+ #include < vector>
4
+
5
+ using namespace std ;
6
+
7
+ class Difference {
8
+ private:
9
+ vector<int > elements;
10
+
11
+ public:
12
+ int maximumDifference;
13
+
14
+ Difference (vector<int > elements) {
15
+ this ->elements = elements;
16
+ }
17
+
18
+ void computeDifference () {
19
+ int maximum = 0 ;
20
+
21
+ for (int i = 0 ; i < this ->elements .size (); i++) {
22
+ for (int j = 0 ; j < this ->elements .size (); j++) {
23
+ int absolute = abs (elements[i] - elements[j]);
24
+ if (absolute > maximum) maximum = absolute;
25
+ }
26
+ }
27
+
28
+ maximumDifference = maximum;
29
+ }
30
+ };
31
+
32
+ int main () {
33
+ int N;
34
+ cin >> N;
35
+
36
+ vector<int > a;
37
+
38
+ for (int i = 0 ; i < N; i++) {
39
+ int e;
40
+ cin >> e;
41
+
42
+ a.push_back (e);
43
+ }
44
+ // Aditya Seth
45
+ Difference d (a);
46
+
47
+ d.computeDifference ();
48
+
49
+ cout << d.maximumDifference ;
50
+
51
+ return 0 ;
52
+ }
Original file line number Diff line number Diff line change
1
+ class Difference (private val elements : IntArray ) {
2
+ var maximumDifference: Int = 0
3
+
4
+ fun computeDifference () {
5
+ var max = 0
6
+
7
+ for (i in elements.indices) {
8
+ for (j in elements.indices) {
9
+ val abs = Math .abs(elements[i] - elements[j])
10
+ if (abs > max) max = abs
11
+ }
12
+ }
13
+ maximumDifference = max
14
+ }
15
+ }
16
+
17
+ fun main (args : Array <String >) {
18
+ val n = Integer .parseInt(readLine())
19
+ val a = readLine()!! .split(' ' )
20
+ val numbers = IntArray (n)
21
+
22
+ for (i in a.indices) {
23
+ numbers[i] = Integer .parseInt(a[i])
24
+ }
25
+
26
+ val difference = Difference (numbers)
27
+ difference.computeDifference()
28
+
29
+ print (difference.maximumDifference)
30
+ }
Original file line number Diff line number Diff line change
1
+ class Difference :
2
+ def __init__ (self , a ):
3
+ self .__elements = a
4
+
5
+ def computeDifference (self ):
6
+ maximum = 0
7
+
8
+ for i in range (len (self .__elements )):
9
+ for j in range (len (self .__elements )):
10
+ absolute = abs (self .__elements [i ] - self .__elements [j ])
11
+ if absolute > maximum :
12
+ maximum = absolute
13
+
14
+ self .maximumDifference = maximum
15
+
16
+
17
+ _ = input ()
18
+ a = [int (e ) for e in input ().split (' ' )]
19
+ #Aditya Seth
20
+ d = Difference (a )
21
+ d .computeDifference ()
22
+
23
+ print (d .maximumDifference )
Original file line number Diff line number Diff line change
1
+ class Difference
2
+ attr_accessor :maximum_difference
3
+ def initialize ( a )
4
+ @elements = a
5
+ @maximum_difference = 0
6
+ end
7
+
8
+ def compute_difference ( )
9
+ max = 0
10
+ for i in 0 ..@elements . length - 1
11
+ for j in 0 ..@elements . length - 1
12
+ diff = @elements [ i ] - @elements [ j ]
13
+ if diff . abs ( ) > max
14
+ max = diff
15
+ end
16
+ end
17
+ end
18
+ @maximum_difference = max
19
+ end
20
+ end
21
+
22
+
23
+ class Solution
24
+ def main
25
+ n = gets . chomp . to_i
26
+ a = [ n ]
27
+ a = gets . chomp . split ( ' ' ) . map ( &:to_i )
28
+ diff = Difference . new ( a )
29
+ diff . compute_difference
30
+ puts diff . maximum_difference
31
+ end
32
+ end
You can’t perform that action at this time.
0 commit comments