본문 바로가기

전체 글310

48] 프로그래머스 문자열을 정수로 바꾸기 앞에 +,-가 올 수도 았고 안 올 수도 있다. #include #include using namespace std; int solution(string s) { int answer = 0; if(s[0]=='-'){ for(int i = s.size()-1 ; i>0; i --) answer += (s[i]-48) * pow(10, s.size()-1 -i); answer = 0- answer; } else if(s[0] == '+'){ for(int i = s.size()-1 ; i>0; i --) answer += (s[i]-48) * pow(10, s.size()-1 -i); } else{ for(int i = s.size()-1 ; i>=0; i --) answer += (s[i]-48) * p.. 2020. 9. 16.
47] 프로그래머스 K번째수 i, j, k의 숫자가 0부터 시작이 아니고 1부터 시작 #include #include using namespace std; vector solution(vector array, vector commands) { vector answer; vectorcopy; for(int i = 0;i 2020. 9. 15.
46★] 프로그래머스 같은 숫자는 싫어 #include #include using namespace std; vector solution(vector arr) { arr.erase(unique(arr.begin(), arr.end()), arr.end()); return arr; } stackoverflow.com/questions/1041620/whats-the-most-efficient-way-to-erase-duplicates-and-sort-a-vector What's the most efficient way to erase duplicates and sort a vector? I need to take a C++ vector with potentially a lot of elements, erase duplicates, and sor.. 2020. 9. 15.
45] 프로그래머스 2016년 코딩테스트 연습 기초부터 차근차근, 직접 코드를 작성해 보세요. programmers.co.kr 각 배열 0번째값 조심 0, THU. #include using namespace std; string solution(int a, int b) { string answer = ""; int arr[13] = {0,31, 29,31,30,31,30,31,31,30,31,30,31}; string date[7] = { "THU", "FRI", "SAT", "SUN", "MON" ,"TUE", "WED"}; int cnt = 0; for(int i = 0;i 2020. 9. 15.
44] 프로그래머스 완주하지 못한 선수 정렬 먼저하고 한명만 완주를 못했으니까 두 벡터가 다른 곳의 위치의 벡터값을 반환해주면 된다, #include #include #include using namespace std; string solution(vector participant, vector completion) { string answer = ""; sort(participant.begin(), participant.end()); sort(completion.begin(), completion.end()); for(int i = 0;i 2020. 9. 14.
43] 프로그래머스 두 개 뽑아서 더하기 코딩테스트 연습 기초부터 차근차근, 직접 코드를 작성해 보세요. programmers.co.kr 벡터에 다 넣어주고 중복값을 제거해주면 된다. #include #include using namespace std; vector solution(vector numbers) { vector answer; for(int i = 0;i 2020. 9. 14.