본문 바로가기
프로그래머스 C++/Level.0

프로그래머스 C++ Level. 0 배열 원소의 길이

by yeni_0224 2023. 3. 24.
728x90
반응형

문자열 배열 strlist가 매개변수로 주어집니다. strlist 각 원소의 길이를 담은 배열을 retrun하도록 solution 함수를 완성해주세요.

#include <string>
#include <vector>

using namespace std;

vector<int> solution(vector<string> strlist) {
    vector<int> answer;
    for(int i = 0; i < strlist.size(); i++){
        answer.push_back(strlist[i].length());
    }    
    return answer;
}

이것은 문법을 알아야하는 문제였다

push_back 네녀석...문법이 중요하다.

length() 함수 : 배열의 길이를 구하는 함수인 것이다.

length() 자리에 size()를 넣어도 정답이 도출되었다.

 

728x90
반응형