1일1알

백준 1205번 등수 구하기 C++ 본문

알고리즘

백준 1205번 등수 구하기 C++

영춘권의달인 2022. 4. 10. 11:35

출처 : https://www.acmicpc.net/problem/1205

 

더 쉬운 방법이 있을 수 있겠지만 생각보다 실수할 여지가 많아보이는 문제였다.

 

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, myScore, p;
	bool first = true;
	bool firstSame = true;
	cin >> n >> myScore >> p;
	int rank = n + 1;
	int renderRank = n + 1;
	vector<int> scores(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> scores[i];
		if (myScore == scores[i]) {
			renderRank = i + 1;
			if (firstSame) {
				rank = i;
				first = false;
				firstSame = false;
			}
		}
		if (myScore > scores[i] && first) {
			renderRank = i;
			rank = i;
			first = false;
		}
	}
	if (renderRank > p) rank = -1;
	cout << rank;
};

'알고리즘' 카테고리의 다른 글

백준 1195번 킥다운 C++  (0) 2022.04.12
백준 1063번 킹 C++  (0) 2022.04.11
백준 6603번 로또 C++  (0) 2022.04.09
백준 16236번 아기 상어 C++  (0) 2022.04.07
백준 1389번 케빈 베이컨의 6단계 법칙  (0) 2022.04.06