https://school.programmers.co.kr/learn/courses/30/lessons/120892
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
function solution(cipher, code)
{
var answer = '';
var arr= [];
for (i=0; i<cipher.length; i++)
{ // cipher의 모든 원소에 대하여,
if ((i+1) % code ==0)
{ // i+1 (왜냐면 1부터 세니까) 을 code로 나눴을때 나눠떨어지면,
arr.push(cipher[i]);
// i (왜냐면 0부터 세니까) 번째 원소를 arr에 집어넣는다.
}
}
answer = arr.join('');
// arr은 배열이니까 다시 문자열로 바꿔주면 정답이 된다.
return answer;
}
+) 230512
const solution = (cipher, code) => {
const newarr=[];
const arr = cipher.split(``);
arr.unshift('a');
for(i=1; i<=cipher.length; i++) {
if (i%code==0){newarr.push(arr[i])}
}
return newarr.join('');
}
230527 python
def solution(cipher, code):
cipher = 'x' + cipher
arr = list(cipher)
newarr = []
for i in range(1, len(arr)):
if i%code == 0:
newarr.append(arr[i])
return ''.join(newarr)
230916 C++
#include <string>
#include <vector>
using namespace std;
string solution(string cipher, int code) {
string answer = "";
cipher = 'x' + cipher;
for(int i=1; i<cipher.size(); i++){
if(i%code==0) answer += cipher[i];
}
return answer;
}
'코딩테스트 > LV. 0' 카테고리의 다른 글
LV. 0 :: 가위 바위 보 (0) | 2023.01.22 |
---|---|
LV. 0 :: 문자 반복 출력하기 (0) | 2023.01.22 |
LV. 0 :: 대문자와 소문자 (0) | 2023.01.22 |
LV. 0 :: n의 배수 고르기 (0) | 2023.01.22 |
LV. 0 :: 다음에 올 숫자 (0) | 2023.01.22 |
댓글