코딩테스트

코딩테스트/프로그래머스(C++)_Level.0

[프로그래머스/C++] Lv.0 배열 만들기 6

문제 코드 #include #include #include using namespace std; vector solution(vector arr) { vector answer; int i = 0; while (i < arr.size()) { if (answer.empty()) { answer.emplace_back(arr[i++]); } else if (answer.back() != arr[i]) { answer.emplace_back(arr[i++]); } else { answer.pop_back(); i++; } } if (answer.empty()) { answer.emplace_back(-1); } return answer; } 문제 해설 -

코딩테스트/프로그래머스(C++)_Level.0

[프로그래머스/C++] Lv.0 배열에 원소만큼 추가하기

문제 코드 #include #include #include using namespace std; vector solution(vector arr) { vector answer; for (int n : arr) { for (int i = 0; i < n; ++i) { answer.emplace_back(n); } } return answer; } 문제 해설 조건에 맞게 for문 사용

코딩테스트/프로그래머스(C++)_Level.0

[프로그래머스/C++] Lv.0 세 개의 구분자

문제 코드 #include #include #include using namespace std; vector solution(string myStr) { vector answer; for (auto& c : myStr) { if (c == 'a' || c == 'b' || c == 'c') { c = ' '; } } stringstream ss(myStr); string str; while (ss >> str) { answer.emplace_back(str); } if (answer.empty()) { answer.emplace_back("EMPTY"); } return answer; } 문제 해설 구분자 3개를 모두 공백으로 바꿔서 stringstream을 이용해서 처리

코딩테스트/프로그래머스(C++)_Level.0

[프로그래머스/C++] Lv.0 문자열 잘라서 정렬하기

문제 코드 #include #include #include #include using namespace std; vector solution(string myString) { vector answer; for (auto& c : myString) { if (c == 'x') { c = ' '; } } stringstream ss(myString); string str; while (ss >> str) { answer.emplace_back(str); } sort(answer.begin(), answer.end()); return answer; }

코딩테스트/프로그래머스(C++)_Level.0

[프로그래머스/C++] Lv.0 x 사이의 개수

문제 코드 #include #include using namespace std; vector solution(string myString) { vector answer; int count = 0; for (auto& c : myString) { if (c == 'x') { answer.emplace_back(count); count = 0; } else { count++; } } answer.emplace_back(count); return answer; }

코딩테스트/프로그래머스(C++)_Level.0

[프로그래머스/C++] Lv.0 공백으로 구분하기 2

문제 코드 #include using namespace std; vector solution(string my_string) { vector answer; stringstream ss(my_string); string str; while(ss >> str) { answer.emplace_back(str); } return answer; }

mane
'코딩테스트' 카테고리의 글 목록 (4 Page)