※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 25812번 문제인 Nice Raises이다.
문제는 아래 링크를 확인하자.

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

 

25812번: Nice Raises

Everyone knows that the UCF Programming Team coaches are the best trainers in the world and turn out some of the best problem solvers and programmers. The UCF team members are heavily sought after by different companies. FAAMGInc has arranged a nice raise

www.acmicpc.net

현재 연봉이 S$인 경우, X$ fixed raise 옵션은 연봉이 X$ 올라가고 double the salary 옵션은 연봉이 S$ 올라간다. 따라서 X와 S의 대소를 비교하는 것으로 fixed raise가 유리한지 double the salary가 유리한지 또는 둘다 같아 계산에서 제외할지를 판단할 수 있다.

 

반복문을 이용해 문제를 해결하자.

 

아래는 제출한 소스코드이다.

#include <iostream>
using namespace std;

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

	int ans = 0;
	int N, salary; cin >> N >> salary;
	while (N--) {
		int x; cin >> x;
		if (x < salary) ans++;
		else if (x > salary) ans--;
	}

	if (ans > 0) cout << 1;
	else if (ans < 0) cout << 2;
	else cout << 0;
}
728x90

+ Recent posts