SKYLIGHT STUDIO

[C++][1267] 핸드폰 요금 본문

Computer Programming/Coding Test(C++)

[C++][1267] 핸드폰 요금

SKY_L 2024. 10. 1. 15:48
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int call_num;

int Y_f, M_f = 0;


int calculate_Y(int a) {	
	return 10 * (a / 30 + 1);
}

int calculate_M(int b) {
	return 15 * (b / 60 + 1);
}

int main()
{
	
	cin >> call_num;

	int* array = new int[call_num]();

	for (int i = 0; i < call_num; i++) {
		cin >> array[i];
		M_f += calculate_M(array[i]);
		Y_f += calculate_Y(array[i]);
	}

	if (Y_f < M_f) {
		cout << "Y " << Y_f;
	}
	if (Y_f == M_f) {
		cout << "Y M " << Y_f;
	}
	else {
		cout << "M " << M_f;
	}
	delete[] array;

}


int* array = new int[];로 동적 배열을 선언해서 수행. 뒤에 ()를 붙이면 원소들이 0으로 초기화된다.

delete[] 잊지 말기

'Computer Programming > Coding Test(C++)' 카테고리의 다른 글

[C++/1076] 저항  (0) 2024.10.08
[C++][2547] 사탕 선생 고창영  (1) 2024.10.02
[C++ 리바이브] C++ 동적 배열  (0) 2024.10.02
[C++][1264] 모음의 개수  (0) 2024.09.29
[C++ 리바이브] Stream, Cout, Cin  (0) 2024.09.26