-
Notifications
You must be signed in to change notification settings - Fork 0
/
programmers_02.cpp
60 lines (58 loc) · 1012 Bytes
/
programmers_02.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <string>
#include<iostream>
#include <vector>
using namespace std;
int solution(int n, vector<int> lost, vector<int> reserve) {
int answer = 0,i;
vector<int> ans;
for (i = 0; i < n; i++) {
ans.push_back(1);
}
for (i = 0; i < lost.size(); i++) {
ans[lost[i]-1]--;
}
for (i = 0; i < reserve.size(); i++) {
ans[reserve[i] - 1]++;
}
for (i = 0; i < n; i++) {
if (ans[i] == 0) {
if (i == 0) {
if (ans[i + 1] > 1) {
ans[i]++;
ans[i+1]--;
}
}
else if (i == n - 1) {
if (ans[i - 1] > 1) {
ans[i]++;
ans[i - 1]--;
}
}
else {
if (ans[i - 1] > 1) {
ans[i]++;
ans[i - 1]--;
}
else if (ans[i + 1] > 1) {
ans[i]++;
ans[i + 1]--;
}
else {
continue;
}
}
}
}
for (i = 0; i < n; i++) {
if (ans[i] > 0) answer++;
}
return answer;
}
int main() {
int n = 3;
vector<int> lost = { 3 };
vector<int> reserve = { 1};
int answer = solution(n, lost, reserve);
cout << answer << endl;
return 0;
}