알고리즘
백준 1205번 등수 구하기 C++
영춘권의달인
2022. 4. 10. 11:35
더 쉬운 방법이 있을 수 있겠지만 생각보다 실수할 여지가 많아보이는 문제였다.
#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;
};