세로 읽기

Subin·2024년 8월 6일

Algorithm

목록 보기
15/69

[내 풀이]

#include <string>
#include <vector>

using namespace std;

string solution(string my_string, int m, int c) {
    string answer = "";

    for(int i=0; i< my_string.length()/m ; i++)
    {
        string part = my_string.substr(m * i, m);
        answer += part[c-1];
    }

    return answer;
}

=> string은 배열로 접근이 가능하다!!


[다른 사람 풀이]

#include <string>
#include <vector>

using namespace std;

string solution(string my_string, int m, int c) {
    string answer = "";
    for(int i=c-1; i<my_string.length(); i+=m)
        answer += my_string[i];
    return answer;
}

c번째 열에서 m 간격 만큼의 문자들을 붙이는 걸로 생각해도 된다

profile
성장하며 꿈꾸는 삶을 살아가고 있는 대학생입니다😊

0개의 댓글