arrow_forward
همه ارسالها
جزئیات ارسال کد#439
برای پسندیدن وارد شوید
1#include <iostream>
2
3using namespace std;
4
5int main()
6{
7 int n;
8 cin >> n;
9 int arr[n];
10 for (int i = 0; i < n; ++i)
11 {
12 cin >> arr[i];
13 }
14
15 int max1 , max2;
16 int index1 = 0;
17 int index2 = 0;
18 max1 = arr[index1];
19 for (int j = 0; j < n; ++j)
20 {
21 if (max1 < arr[j])
22 {
23 max1 = arr[j];
24 index1 = j;
25 }
26 }
27 if (index1 == 0)
28 {
29 index2 = 1;
30 }
31 max2 = arr[index2];
32 for (int i = 0; i < n; ++i)
33 {
34 if (max2 < arr[i] && arr[i] < max1)
35 {
36 max2 = arr[i];
37 index2 = i;
38 }
39 }
40 int space;
41 if (index1 > index2)
42 {
43 space = index1 - index2;
44 }
45 else
46 {
47 space = index2 - index1;
48 }
49 cout << space;
50
51
52 return 0;
53}
کد ارسالشده برای داوری خودکار هاتکدز
UTF-8