Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Programmers/Level2/40_MagicElevator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <string>
#include <vector>

using namespace std;

// 마법의 엘리베이터
// https://school.programmers.co.kr/learn/courses/30/lessons/148653?language=cpp

int solution(int storey) {
int count = 0;

while(storey != 0)
{
int mod = storey % 10;
storey /= 10;

if(mod > 5)
{
count += (10-mod);
storey += 1;
}
else if(mod == 5 && (storey%10) >= 5)
{
count += 5;
storey += 1;
}
else
{
count += mod;
}

}

return count;
}
23 changes: 23 additions & 0 deletions Programmers/Level2/42_DotPlotting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <string>
#include <vector>
#include <cmath>

using namespace std;

// 점 찍기
// https://school.programmers.co.kr/learn/courses/30/lessons/140107

long long solution(int k, int d) {
long long answer = 0;
long long limit = (long long)d * (long long)d;

for(int a = 0; a <= d; a += k)
{
long long squared_maxB = limit - (long long)a* (long long)a;
long long maxB = (long long)sqrt(squared_maxB);

answer += (maxB / k) + 1;
}

return answer;
}
31 changes: 31 additions & 0 deletions Programmers/Level2/43_SelectTangerines.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

// 귤 고르기
// https://school.programmers.co.kr/learn/courses/30/lessons/138476

int solution(int k, vector<int> tangerine) {
int answer = 0;
unordered_map<int, int> um;
for(int val : tangerine)
{
um[val]++;
}
vector<pair<int,int>> sorted(um.begin(), um.end());
sort(sorted.begin(), sorted.end(), [](const pair<int,int> &a, const pair<int,int> &b){
return a.second > b.second;
});

for(auto& val : sorted)
{
k -= val.second;
answer++;
if(k<=0) break;
}

return answer;
}