Codechef crypthon contest.
Codechef crypthon contest : hard code crypt problem solution in java.
import java.util.*;
class cf
{
static void calc(int[] arr , int n) {
int count = 0;
for(int i=0;i<n-3;i++) {
for(int j=i+1;j<n-2;j++) {
int diff = arr[j] - arr[i];
for(int k=j+1;k<n-1;k++) {
for(int l=k+1;l<n;l++) {
if(arr[l] - arr[k] == diff && arr[k] - arr[j] == diff)
{
System.out.println(arr[i]+" : "+arr[j]+" : "+arr[k]+" : "+arr[l]);
count ++;
}
}
}
}
}
System.out.println(count);
}
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
try
{
int n = input.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++) {
arr[i] = input.nextInt();
}
calc(arr,n);
}
catch(Exception e){
return;
}
}
}
11
3 5 3 6 3 4 10 4 5 2 6
3 : 4 : 5 : 6
3 : 4 : 5 : 6
3 : 4 : 5 : 6
3 : 4 : 5 : 6
3 : 4 : 5 : 6
3 : 4 : 5 : 6
Count : 6