Notice
Recent Posts
Recent Comments
Link
250x250
«   2025/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
Archives
Today
Total
관리 메뉴

피너클의 it공부방

백준 1267 핸드폰 요금 (c++) : 피너클 본문

백준

백준 1267 핸드폰 요금 (c++) : 피너클

피너클 2022. 6. 27. 14:48
728x90
반응형

https://www.acmicpc.net/problem/1267

 

1267번: 핸드폰 요금

동호가 저번 달에 이용한 통화의 개수 N이 주어진다. N은 20보다 작거나 같은 자연수이다. 둘째 줄에 통화 시간 N개가 주어진다. 통화 시간은 10,000보다 작거나 같은 자연수이다.

www.acmicpc.net

간단한 구현문제다.

#include <iostream>

using namespace std;

int n;
int arr[21];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	int y = 0, m = 0;
	for (int i = 0; i < n; i++) {
		int a = arr[i];
		while (a >= 0) {
			a -= 30;
			y += 10;
		}
		a = arr[i];
		while (a >= 0) {
			a -= 60;
			m += 15;
		}
	}
	if (y < m) cout << "Y " << y << endl;
	else if (y > m) cout << "M " << m << endl;
	else cout << "Y M " << y << endl;
}

전체코드다.

728x90
반응형
Comments