[백준/BOJ]15720. 카우버거 [Bronze1]

jychan99·2021년 8월 24일
0
post-thumbnail
  1. 카우버거

문제출처 : https://www.acmicpc.net/problem/15720

나는 무식하게 내림차순으로 정렬후, 세트로 묶어서 가격을 다더했다.
분명 더 쉬운 방법이 있을것이다...그리디니까...

code

#include <stdio.h>
void Sort(int arr[],int s) //정렬알고리즘을 함수로
{
	int temp=0;
	for (int i = 0; i < s-1; i++)
		for (int j = 0; j < s - 1 - i; j++) //버블정렬이라고 하는 정렬방식이다.
			if (arr[j] < arr[j + 1])
			{
				temp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = temp;
			}
}
int main()
{
	int B, C, D,index=0,j,total=0;
	int burger[1000] = { 0 }, side[1000] = { 0 }, drink[1000] = { 0 };
	scanf("%d %d %d", &B, &C, &D);
	index = (B < C) ? (B < D) ? B : D : (C < D) ? C : D; //버거, 사이드, 음료중 가장 적게 입력                                                             //받은것 색출 그래야 세트로 만들 수 있는 개수가 정해짐
	for (j = 0; j < B; j++)
	{
		scanf(" %d ", &burger[j]);
		total += burger[j];
	}
	for (j = 0; j < C; j++)
	{
		scanf(" %d ", &side[j]);
		total += side[j];
	}
	for (j = 0; j < D; j++)
	{
		scanf(" %d ", &drink[j]);
		total += drink[j];
	}
	Sort(burger, B); Sort(side, C); Sort(drink, D); //버블정렬 함수 호출해서 내림차순으로 정렬
	printf("%d\n", total); //할인적용전 총가격
	for (j = 0; j < index; j++) // 10%할인이니까 *0.9를해줌
	{
		burger[j] *= 0.9;
		side[j] *= 0.9;
		drink[j] *= 0.9;
	}
	total = 0;
	for (j = 0; j < B; j++)
		total += burger[j];
	for (j = 0; j < C; j++)
		total += side[j];
	for (j = 0; j < D; j++)
		total += drink[j];
	printf("%d", total); //할인이 적용된 총가격
	return 0;
}
profile
내가 지금 두려워 하고 있는 일이 바로 내가 지금 해야 할 일이다. 🐥

0개의 댓글