문제 설명
문자열 my_string과 정수 배열 index_list가 매개변수로 주어집니다. my_string의 index_list의 원소들에 해당하는 인덱스의 글자들을 순서대로 이어 붙인 문자열을 return 하는 solution 함수를 작성해 주세요.
using System;
public class Solution {
public string solution(string my_string, int[] index_list) {
string answer = "";
for(int i = 0; i < index_list.Length; i++)
{
answer += my_string[index_list[i]];
}
return answer;
}
}
다른 풀이
using System;
using System.Text;
public class Solution {
public string solution(string my_string, int[] index_list)
{
var sb = new StringBuilder();
foreach(int n in index_list)
sb.Append(my_string[n]);
return sb.ToString();
}
}
using System;
public class Solution {
public string solution(string my_string, int[] index_list) {
string answer = "";
for(int i = 0 ; i < index_list.Length ; i++){
answer += my_string[index_list[i]].ToString();
}
return answer;
}
}
문자열의 뒤의 n글자 (0) | 2024.06.11 |
---|---|
9로 나눈 나머지 (1) | 2024.06.11 |
간단한 논리 연산 (0) | 2024.06.11 |
콜라츠 수열 만들기 (0) | 2024.06.10 |
카운트 업 (0) | 2024.06.10 |