Make Unreal REAL.
article thumbnail
Level 1. 성격 유형 검사하기

Level 1. 성격 유형 검사하기 좀 더 쉽게 풀 수 있었는데 연산자 오버로딩을 쓰고 싶어서 좀 길어졌다. #include #include #include using namespace std; class Personality { int scores[4] = {0}; public: Personality() {} bool isReversed(string& survey) { return (survey[0] == 'T') || (survey[0] == 'F') || (survey[0] == 'M') || (survey[0] == 'N'); } int& operator [] (string& survey) { const char* c_string = survey.c_str(); if (strchr(c_string..

article thumbnail
Level 1. 신고 결과 받기

Level 1. 신고 결과 받기 (내가 신고한 사람, 나를 신고한 사람, 정지 여부)를 저장하는 사용자 정점으로 구성된 방향 그래프를 만들어 해결했다. 내가 신고한 사람을 나가는 간선, 나를 신고한 사람을 들어오는 간선으로 간주했다. 중복을 허용하지 않도록 unordered_set을 사용했고 인접 리스트 방식이라고 할 수 있다. 그래프를 구성하면서 신고 횟수가 k번이 넘었는지 확인하고, 마지막에 내가 신고한 사람 중 bSuspended가 true인 개수를 세어 해결했다. #include #include #include #include #include #include using namespace std; struct user { unordered_set reports; unordered_set report..

article thumbnail
Level 1. 바탕화면 정리

Level 1. 바탕화면 정리 첫 매칭 위치를 반환하는 string.find()와 마지막 매칭 위치를 반환하는 string.rfind()를 이용해 해결했다. #include #include #include #include using namespace std; vector solution(vector wallpaper) { int lux = INT_MAX, luy = INT_MAX; int rdx = INT_MIN, rdy = INT_MIN; int width = wallpaper.front().size(), height = wallpaper.size(); int x, pos; for (x = 0; x < height; ++x) if (wallpaper[x].find('#') != string::npos)..

article thumbnail
Level 1. 둘만의 암호

Level 1. 둘만의 암호 처음 봤을 때 귀찮은 문제 같아서 미뤄 뒀었는데 막상 풀어보니 쉬운 문제였다. 매번 skip에서 s의 알파벳을 찾지 않고 unordered_map에 저장하여 바로 확인했다. #include #include using namespace std; string solution(string s, string skip, int index) { unordered_map umap; for (char c : skip) umap[c] = true; for (char& c : s) { int n = index; while (n) if (umap[c = 'a' + (++c - 'a') % 26] == false) --n; } return s; }

article thumbnail
Level 1. 부족한 금액 계산하기

Level 1. 부족한 금액 계산하기 #include #include using namespace std; long long solution(int price, int money, int count) { return max(0, price * count * (count + 1) / 2 - money); }

article thumbnail
Level 1. 신규 아이디 추천

Level 1. 신규 아이디 추천 디버깅이 수월하도록 각 단계를 함수로 나눴다. string은 다양한 자료구조 함수를 지원하기 때문에 문자열보다는 자료구조처럼 활용했다. step3()에서 unique() 함수를 저렇게 활용하면 연속된 문자를 제거할 수 있다. #include #include #include using namespace std; void step1(string& s) { transform(s.begin(), s.end(), s.begin(), [](char c) { return isalpha(c) ? tolower(c) : c; }); } void step2(string& s) { auto it = remove_if(s.begin(), s.end(), [](char c) { return !..

검색 태그