Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.

EIUARRAY - Array algorithms

Chương trình sau bao gồm một số giải thuật cơ bản về Array, em hãy hoàn thiện các giải thuật này và chương trình kiểm tra.

 

Input

Dòng đầu tiên gồm hai số nguyên tương ứng là chiều dài của dãy số và số câu lệnh. Dòng thứ hai là dãy số

5 5
5 2 7 3 5
findMin
findMax
average
indexOf 3
lastIndexOf 5

Output

2
7
4.4
3
4

Program

import java.util.Scanner;

public class ArrayAlgorithms {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] numbers = new int[n];
		for (int j = 0; j < n; j++) {
			numbers[j] = sc.nextInt();
		}

		for (int i = 0; i < m; i++) {
			String command = sc.next();

			long result = 0;
			switch (command) {
			case "findMax":
				result = findMax(numbers);
				break;
			case "findMin":
				result = findMin(numbers);
				break;
			}
			System.out.println(result);

			// Add your code here

		}
	}

	static int findMax(int[] numbers) {
		// Add your code here
		return 0;
	}

	static int findMin(int[] numbers) {
		// Add your code here
		return 0;
	}

	static double average(int[] numbers) {
		// Add your code here
		return 0;
	}

	static int sum(int[] numbers) {
		// Add your code here
		return 0;
	}

	/**
	 * @Desciption:
	 * @Hint: find maximum number in the array, then check which number is
	 */
	static int countMax(int[] numbers) {
		// Add your code here
		return 0;
	}

	/**
	 * @Desciption: sum all odd numbers in array
	 * @Hint: what is odd number, how to check?
	 */
	static int sumOddNumber(int[] numbers) {
		// Add your code here
		return 0;
	}

	static int countEvenNumber(int[] numbers) {
		// Add your code here
		return 0;
	}

	static int indexOf(int[] numbers, int value) {
		// Add your code here
		return -1;
	}

	static int lastIndexOf(int[] numbers, int value) {
		// Add your code here
		return -1;
	}

	/**
	 * @Desciption: find minimum difference between two consecutive numbers in an
	 *              array
	 * @Hint: minimum of Math.absolute(array[i+1] - array[i])
	 */
	static int findMinDistance(int[] numbers) {
		// Add your code here
		return 0;
	}

	/**
	 * @Desciption: Check if first number equal last number, second number equal
	 *              second to last number, and so on...
	 * @Hint: i-th number equal (length-1-i)-th number
	 */
	static boolean isPalindrome(int[] numbers) {
		// Add your code here
		return false;
	}

	/**
	 * @Desciption: Check if number is in array
	 */
	static boolean contains(int[] numbers, int number) {
		// Add your code here
		return false;
	}

	/**
	 * @Desciption: Check if array has duplicated numbers
	 * @Hint: Should check every pair of number, array[i] vs. array[j], i != j
	 */
	static boolean hasDuplicated(int[] numbers) {
		// Add your code here
		return false;
	}

	/**
	 * @Desciption: Check if array has two numbers A and B where A % B = 0
	 * @Hint: Should check every pair of number, array[i] vs. array[j], i != j *
	 */
	static boolean hasDivisor(int[] numbers) {
		// Add your code here
		return false;
	}
}

Added by:Ha Minh Ngoc
Date:2015-01-04
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:CSHARP C++ 4.3.2 CPP CPP14 CPP14-CLANG FSHARP GO JAVA JS-MONKEY NODEJS PHP PYTHON PYPY PYTHON3 RUBY SQLITE SWIFT VB.NET
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.