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

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

verified
وضعیت داوری نهایی: پذیرفته شد
terminal
زبان برنامه‌نویسی: Java
schedule
ارسال‌کننده و زمان:
khashayar moeinfar (۱ سال پیش)
descriptionMain.java ۵۷ خط • ۱٫۶ کیلوبایت
1////TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
2//// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
3//void main() {
4// //TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
5// // to see how IntelliJ IDEA suggests fixing it.
6// IO.println(String.format("Hello and welcome!"));
7//
8// for (int i = 1; i <= 5; i++) {
9// //TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
10// // for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
11// IO.println("i = " + i);
12// }
13//}
14
15
16import java.util.Scanner;
17public class Main {
18 public static void main(String[] args) {
19 Scanner sc = new Scanner(System.in);
20 int n = sc.nextInt();
21
22 int[] arr = new int[n];
23 for (int i=0; i<n; i++){
24 arr[i]=sc.nextInt();
25 }
26 int[] arr2=new int[n];
27 for(int i=0;i<n;i++){
28 arr2[i]=arr[i];
29 }
30
31 for (int i=0;i<n;i++){
32 for (int j=i+1;j<n;j++){
33 int temp=0;
34 if (arr[i]>arr[j]){
35 temp=arr[i];
36 arr[i]=arr[j];
37 arr[j]=temp;
38 }
39 }
40 }
41
42 int one =0;
43 int two =0;
44 for (int i=0;i<n;i++){
45 if (arr2[i]==arr[n-1]){
46 one=i;
47 }
48 else if (arr2[i]==arr[n-2]) {
49 two=i;
50
51 }
52 }
53 System.out.print(Math.abs(one-two));
54
55
56 }
57}
کد ارسال‌شده برای داوری خودکار هاتکدز UTF-8