[C++] 프로그래머스 문자열 압축 2020 KAKAO BLIND RECRUITMENT
·
Algorithm/Programmers
#include #include #include #include using namespace std; int solution(string s) { int answer = s.size(); if(answer == 1) return 1; for(int i = 1; i = s.size()) //다음 단어가 단어 길이를 넘을때 { if(counts == 1) { temp += s.substr(j); break; } else { temp += to_string(counts) + currtemp; break; } } } if(answer > temp.size()) answer = temp.size(); } return answer; } 풀이 문자열의 길이가 2이하일 경우 최소 압축가능한 수가 2이므로 return ..
[C++] 프로그래머스 카카오 1차 온라인 코딩테스트 5번 문제 뉴스 클러스터링(난이도: 중)
·
Algorithm/Programmers
#include #include #include #include #include #include #include using namespace std; #include int solution(string str1, string str2) { int answer = 0; float intersections = 0; float unions = 0; transform(str1.begin(), str1.end(), str1.begin(), ::tolower); transform(str2.begin(), str2.end(), str2.begin(), ::tolower); vector str1v; vector str2v; for (int i = 0; i < str1.size() - 1; i++) { if (isalp..
문자열 관리
·
C++/Basic
#include str1.substr(i, n); - 해당 문자열에서 i번부터 n개를 반환한다. - 을 선언해야된다.
알파벳 대소문자 관리
·
C++/Basic
#include isalpha(str[i]) - 알파벳이 대문자이면 2 소문자이면 1 그 외면 0을 리턴하는 함수 - 을 선언해야된다. #include transform(str1.begin(), str1.end(), str1.begin(), ::tolower); - 문자열의 처음부터 끝까지 소문자로 치환 - ::toupper를 사용하면 대문자로 치환한다. - 을 선언해야된다.
[C++] 프로그래머스 베스트앨범 해시
·
Algorithm/Programmers
#include #include #include #include #include using namespace std; bool genlistSort(pair a, pair b) { return a.second > b.second; } bool playslistSort(pair a, pair b) { //어차피 기본정렬이 오름차순이여서 필요가 없었다. //if(a.first > b.first) //{ // return a.first > b.first; //} //else if(a.first == b.first) //{ // return a.second b.first; } vector solution(vector genres, vector plays..
[C++] 프로그래머스 위장 해시
·
Algorithm/Programmers
#include #include #include using namespace std; int solution(vector clothes) { int answer = 1; map data; for(int i = 0; i < clothes.size(); i++) { data[clothes[i][1]] += 1; } for(auto d : data) { answer *= d.second + 1; } return answer - 1; } 풀이 의상의 종류의 개수을 받는다. 의상의 종류의 개수에서 선택안함을 추가하여 +1씩하고 모두 곱해준다. 모두 선택안함은 없으므로 -1 해준다. 예를 들어 얼굴 / 동그란 안경, 검정 선글라스 상의 / 파란색 티셔츠 인 경우를 생각해보자. 얼굴을 선택안한다는 선택지 상의를 선택..