-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpermutedarithmeticsequence.java
86 lines (56 loc) · 1.43 KB
/
permutedarithmeticsequence.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.util.ArrayList;
import java.util.Scanner;
public class permutedarithmeticsequence {
static ArrayList<String> results = new ArrayList<>();
public static void SelectionSort(int[] a){
for(int i=0; i < a.length-1; i++) {
int mindex=i;
for(int j=i+1; j<a.length; j++){
if(a[j] < a[mindex])
mindex = j;
}
if(mindex != i) {
int t = a[i];
a[i] = a[mindex];
a[mindex]= t;
}
}
}
public static void resolve(int[] list){
int len = list.length;
for(int i=0; i < len-2; i++){
if(!(list[i+1]-list[i] == list[i+2] - list[i+1])){
break;
}else if(i == len-3){
results.add("arithmetic");
return;
}
}
SelectionSort(list);
for(int i=0; i < len-2; i++){
if(!(list[i+1]-list[i] == list[i+2] - list[i+1])){
break;
}else if(i == len-3){
results.add("permuted arithmetic");
return;
}
}
results.add("non-arithmetic");
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int lines = scan.nextInt();
for(int j=0; j<lines; j++){
int times = scan.nextInt();
int[] nums = new int[times];
for(int i=0; i < times; i++){
nums[i] = scan.nextInt();
}
resolve(nums);
}
for(int i=0; i<results.size(); i++){
System.out.println(results.get(i));
}
scan.close();
}
}