본문 바로가기

전체 글332

2016년 *2016년 a월 b일 요일 구하기. 16년 1월 1일은 금요일. 윤년(2.29) #include using namespace std; string solution(int a, int b) { string answer = ""; vector day = {"THU","FRI","SAT","SUN","MON","TUE","WED"}; vector month = {31,29,31,30,31,30,31,31,30,31,30,31}; int count = 0; for(int i = 0; i 2019. 9. 5.
K번째 수 *k번째 수(정렬) #include #include #include using namespace std; vector solution(vector array, vector commands) { vector answer; for(auto elem : commands) { vector temp; for(int i = elem[0] - 1; i 2019. 9. 5.
소수의 합 *소수의 합(기타) 2부터 N까지의 모든 소수의 합을 구하기. #include using namespace std; long long solution(int N) { long long answer = 0; vector nums; nums.assign(N + 1, 1); // N + 1 만큼의 배열 개수를 1의 값으로 채운다. for(int i = 2; i 2019. 9. 5.
*탑(스택) 수평 직선에 탑 N대를 세웠습니다. 발사한 신호는 신호를 보낸 탑보다 높은 탑에서만 수신합니다. 또한, 한 번 수신된 신호는 다른 탑으로 송신되지 않습니다. #include #include using namespace std; vector solution(vector heights) { vector answer; answer.push_back(0); for(int i = 1; i = 0; j--) { if(heights[j] > heights[i]) { answer.push_back(j + 1); break; } else if(j == 0) { answer.push_back(0); } } } return answer; }Colored by Color Scriptercs 2019. 9. 5.
위장 *위장(해시맵) clothes의 각 행은 [의상의 이름, 의상의 종류]로 이루어져 있습니다. 같은 이름을 가진 의상은 존재하지 않습니다. 스파이는 하루에 최소 한 개의 의상은 입습니다. [["yellow_hat", "headgear"], ["blue_sunglasses", "eyewear"], ["green_turban", "headgear"]] #include #include #include using namespace std; int solution(vector clothes) { int answer = 0; map tmap; for(auto elem : clothes) { string key = elem.second; if(tmap.end() != tmap.find(key)) { tmap[key]+.. 2019. 9. 5.
전화번호 목록 *전화번호 목록(해시,정렬) 전화번호를 담은 배열 phone_book의 어떤 번호가 다른 번호의 접두어인 경우가 있으면 false를 아니면 true를 리턴 #include #include #include using namespace std; bool solution(vector phone_book) { bool answer = true; sort(phone_book.begin(), phone_book.end()); string temp = phone_book[0]; for(int i = 1; i 2019. 9. 5.