arrow_forward همه ارسال‌ها

جزئیات ارسال کد#438

verified
وضعیت داوری نهایی: پذیرفته شد
terminal
زبان برنامه‌نویسی: C++
schedule
ارسال‌کننده و زمان:
Faraz Azadi (۲ سال پیش)
descriptionsolution.cpp ۴۹ خط • ۸۳۰ بایت
1#include <iostream>
2using namespace std;
3int main()
4{
5 int n;
6 cin >> n;
7 int arr[n];
8
9 for (int i = 0; i < n; i++)
10 {
11 cin >> arr[i];
12 }
13
14 int max1 = arr[0];
15 int andis1 = 0;
16 for (int b = 1; b < n; b++)
17 {
18 if (arr[b] > max1)
19 {
20 max1 = arr[b];
21 andis1 = b;
22 }
23 }
24
25 int max2 = arr[0];
26 int andis2 = 0;
27 int k = abs(max1 - max2);
28
29 if (max1 == arr[0])
30 {
31 andis2 = 1;
32 max2 = arr[1];
33 k = abs(max2 - max1);
34 }
35
36 for (int c = 0; c < n; c++)
37 {
38 if ((max1 - arr[c]) < k && c != andis1)
39 {
40 max2 = arr[c];
41 andis2 = c;
42 k = abs(max1 - max2);
43 }
44 }
45
46 cout << abs(andis1 - andis2);
47
48 return 0;
49}
کد ارسال‌شده برای داوری خودکار هاتکدز UTF-8