본문 바로가기
프로그래머스코딩테스트연습풀이/C++

[프로그래머스/C++] 배열 만들기 5

by 코코쵸마 2025. 3. 6.

문제

문자열 배열 intStrs와 정수 k, s, l가 주어집니다. intStrs의 원소는 숫자로 이루어져 있습니다.

배열 intStrs의 각 원소마다 s번 인덱스에서 시작하는 길이 l짜리 부분 문자열을 잘라내 정수로 변환합니다. 이때 변환한 정수값이 k보다 큰 값들을 담은 배열을 return 하는 solution 함수를 완성해 주세요.

 

솔루션

#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<string> intStrs, int k, int s, int l) {
    vector<int> answer;
    for(int i = 0; i < intStrs.size(); i++){
        if(stoi(intStrs[i].substr(s,l)) > k){
            answer.push_back(stoi(intStrs[i].substr(s,l)));
        }
    }
    return answer;
}

 

https://school.programmers.co.kr/learn/courses/30/lessons/181912

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr