Algorithm/backjoon

[백준] 1267번 핸드폰 요금 (python,c++)

유쾌한고등어 2023. 3. 15. 11:10

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

 

1267번: 핸드폰 요금

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

www.acmicpc.net

 파이썬 정수몫은 // 임에 유의하자! (파이썬 C++ 같이 푸려다보니까 헷갈렸다ㅜ.)


SOLUTION CODE

# PYTHON

N = int(input())
li = list(map(int,input().split()))


Y = 0
M = 0

for i in li:
    # 영식 요금제
    Y+= (i // 30+1)*10
    M+= (i // 60+1)*15
    
if Y<M:
    print("Y",Y)
elif Y>M:
    print("M",M)
else:
    print("Y M", Y)

 

# C++

#include <iostream>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int N,Y=0,M=0;
	int in;
	
	cin >> N;
	
	for(int i=0;i<N;i++){
	    cin >> in;
	    Y+=(in/30+1)*10;
	    M+=(in/60+1)*15;
	}
	if(M<Y) cout<<"M "<<M;
	else if(M>Y) cout<<"Y "<<Y;
	else if(M==Y) cout<<"Y M "<<M;
	
	return 0;
}