#include "..\CookHeader.h"

Array <int> selctionSort(Array <int> ary) {
	int n = len(ary);
	for (int cycle = 0; cycle < n - 1; cycle++) {
		int minIdx = cycle;
		for (int i = cycle + 1; i < n; i++) {
			if (ary[minIdx] > ary[i])
				minIdx = i;
		}
		int tmp = ary[cycle];
		ary[cycle] = ary[minIdx];
		ary[minIdx] = tmp;
	}
	return ary;
}

int main() {

	Array <int> scoreAry;

	randomInit(0, 1000);
	for (int i = 0; i < 20; i++) {
		int num = cookRandom(gen);
		scoreAry.push_back(num);
	}

	print("전체 펀치 점수 -->");
	printArray(scoreAry);
	scoreAry = selctionSort(scoreAry);
	print("점수 정렬 후 -->");
	printArray(scoreAry);
	int midScore = scoreAry[len(scoreAry) / 2];
	print("점수 중앙값 -->");
	println(midScore);

	int sumScore = 0;
	int avgScore;
	int count = 0;

	for (int i=0; i<len(scoreAry); i++) {
		if (scoreAry[i] >= midScore * 1.5)
			continue;
		else if (scoreAry[i] <= midScore / 3)
			continue;
		else {
			count++;
			sumScore += scoreAry[i];
		}
	}
	avgScore = sumScore / count;
	print("정상적인 펀치의 평균값 -->");
	print(avgScore);
}