개발/문제풀이
-
프로그래머스 17678 추석 트래픽 [C++]개발/문제풀이 2020. 5. 1. 18:56
https://programmers.co.kr/learn/courses/30/lessons/17676 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include #include #include using namespace std; // 시간 문자열을 밀리초 단위 int로 변환 int timeToSec(const string time) { // 더 좋은 방법이 있을 텐데 int h = stoi(time.substr(0, 2)); int m = stoi(time.substr(3, 2)); int s = stoi(time.s..
-
프로그래머스 17683 방금그곡 [C++]개발/문제풀이 2020. 4. 24. 14:26
오류를 찾는 데 한참 걸렸고, 문자열 처리에 관해 많이 공부한 문제가 되어서 정리. removeSharp() 함수는 주어진 멜로디에서 #을 찾으면 전 문자를 소문자로 변경하고 #을 삭제한다. 문자열의 길이가 변화하므로 index도 변경해야 하므로 주의. getMusicLen() 함수는 "HH:MM" 형식의 시간을 나타내는 문자열 두 개에서 정수 시간 간격을 반환한다. 문제의 조건에 따라 00:00을 넘어서 재생되는 경우가 없으므로 시간 간격이 음수가 되는 경우를 처리할 필요는 없다. for(string info : musicinfos) 반복문에서 각 문자열 처리를 수행하고, info의 melody를 재생된 시간에 맞게 변환한다. 그리고 string::find함수를 통해 일치여부를 확인할 수 있는데 이 함..