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

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

verified
وضعیت داوری نهایی: پذیرفته شد
terminal
زبان برنامه‌نویسی: C++
schedule
ارسال‌کننده و زمان:
Armin Fattahpuor (۲ سال پیش)
descriptionsolution.cpp ۵۸ خط • ۶۶۵ بایت
1#include <iostream>
2
3using namespace std;
4
5int main()
6{
7 int n ,max1 , max2, a, b, c, x;
8 int index;
9 int index0;
10 int z;
11 cin >> n;
12 cin >> a;
13 cin >> b;
14 max1 = a;
15 max2 = b;
16 if (max2 > max1)
17 {
18 x = max2;
19 max2 = max1;
20 max1 = x;
21 }
22
23 for (int i = 2; i < n; ++i)
24 {
25 cin >> c;
26 if (c > max1)
27 {
28 max2 = max1;
29 max1 = c;
30 index = i;
31 }
32 else if (c > max2)
33 {
34 max2 = c;
35 index0 = i;
36 }
37 }
38 if (a == max1)
39 {
40 index = 0;
41 }
42 if (a == max2)
43 {
44 index0 = 0;
45 }
46
47 if (b == max2)
48 {
49 index0 = 1;
50 }
51 if (b == max1)
52 {
53 index = 1;
54 }
55 z = abs(index - index0);
56 cout << z;
57 return 0;
58}
کد ارسال‌شده برای داوری خودکار هاتکدز UTF-8