알고리즘/프로그래머스 1단계

프로그래머스 - 암호 해독 - C++

게임만드는학생 2023. 8. 11. 00:20

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

#include <string>
#include <vector>

using namespace std;

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

 

설명

 

code번째 문자만을 골라내야하는 문제이다.

따라서 for문에 code-1 부터 i+=code 로 code번째 문자를 answer에 추가하면 된다.