Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
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
Tags
more
Archives
Today
Total
관리 메뉴

Visual Studio

백준 온라인 저지: 4909 Judging Olympia 본문

Problem Solving

백준 온라인 저지: 4909 Judging Olympia

emacser 2022. 6. 7. 05:26
 

4909번: Judging Olympia

For years, a group of Regional Contest Directors (RCDs) of the ACM International Collegiate Programming Contest (ICPC) have been unsatisfied with the way contest submissions get ranked. The group sees it is academically wrong to emphasize the importance of

www.acmicpc.net

영어 문제이다.

각 라인마다 1 이상 10 이하의 6개의 정수가 주어지는데,최댓값과 최솟값을 제외한 4개의 값의 평균을 구하는 쉬운 태스크이다.

종료조건은 0 0 0 0 0 0 이 입력으로 주어졌을 때이다.

// 입력
// 매 줄마다 0 이상 10 이하의 정수 6개가 주어짐.
// "0 0 0 0 0 0" 은 입력의 끝을 의미함.

// 출력
// 각 줄마다 최고점과 최저점을 제외한 4개 항목의 점수의 평균을 구해야 함.
// 소숫점 맨 끝 0을 제외한 실수를 출력해야함.

#include <cstdio>

int main()
{
	while (true)
	{
		int scoreSum = 0;
		int scoreMax = 0;
		int scoreMin = 10;
		for (int i = 0; i < 6; ++i)
		{
			int score = 0;
			scanf("%d", &score);

			scoreSum += score;
			scoreMax = score > scoreMax ? score : scoreMax;
			scoreMin = score < scoreMin ? score : scoreMin;
		}

		if (scoreSum == 0)
		{
			break;
		}

		printf("%.3g\n", (scoreSum - scoreMax - scoreMin) / 4.0f);
	}
}

6개의 점수를 모두 저장할 필요는 없고, 입력이 들어올때마다 sum, min, max를 갱신해주면 된다.

입력은 1 이상 10 이하인 정수이므로, sum이 0이면 입력은 당연히 0 0 0 0 0 0 이므로 이것을 이용해 종료조건을 체크할

수 있다.

 

주의할 점은, 소숫점 오른쪽에 0 패딩이 존재하면 안된다는 것이다.

 

printf 포맷 중 %g를 사용하면 float 자료형을 zero-padding 없이 출력할 수 있다.

%g에 대해서는 아래 포스트를 참고하자.

 

C 언어 에서 %e와 %g에 대해서

#include int main(void) { printf(" %%e and %%E\n"); printf("%e \n", 0.0001239535943); //소수점 이하 0아닌 숫자 7개만살림 (8번째에서 반올림) printf("%E \n", 0.0001239535943); //소수점 이하 0아닌 숫자..

blog.daum.net