반응형
https://programmers.co.kr/learn/courses/30/lessons/17680
LRU 구현
#include<iostream>
#include <string>
#include <vector>
#include<algorithm>
using namespace std;
bool check(string str1,string str2)
{
for(int i = 0; i < str1.size(); i++)
{
if(str1[i] >= 'A' && str1[i] <= 'Z')
{
str1[i] += 32;
}
}
for(int i = 0; i < str2.size(); i++)
{
if(str2[i] >= 'A' && str2[i] <= 'Z')
{
str2[i] += 32;
}
}
if(str1 == str2)
{
return true;
}
return false;
}
int solution(int cacheSize, vector<string> cities) {
int answer = 0;
vector<pair<int,string> > vec;
for(int i = 0; i < cities.size(); i++)
{
for(int j = 0; j < vec.size(); j++)
{
vec[j].first++;
}
bool flag = false;
for(int j = 0; j < vec.size(); j++)
{
if(check(vec[j].second,cities[i]))
{
answer += 1;
flag = true;
vec[j].first = 0;
break;
}
}
if(!flag)
{
answer += 5;
if(vec.size() < cacheSize)
{
vec.push_back({0,cities[i]});
}
else
{
sort(vec.begin(),vec.end());
if(vec.size())
{
vec[cacheSize-1] = {0,cities[i]};
}
}
}
}
return answer;
}
반응형
'Algorithm' 카테고리의 다른 글
삼성이의 쇼핑 (0) | 2020.05.28 |
---|---|
2018 KAKAO BLIND RECRUITMENT[1차] 뉴스 클러스터링 (0) | 2020.05.08 |
2018 KAKAO BLIND RECRUITMENT[1차] 다트 게임 (0) | 2020.05.08 |
2018 KAKAO BLIND RECRUITMENT[1차] 비밀지도 (0) | 2020.05.08 |
2018 KAKAO BLIND RECRUITMENT[1차] 추석 트래픽 (0) | 2020.05.08 |