Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

개발 일지

핸드폰 번호 가리기 본문

코딩 테스트/프로그래머스

핸드폰 번호 가리기

포카리tea 2021. 6. 17. 22:32

● 문제 설명

프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다.
전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부 *으로 가린 문자열을 리턴하는 함수, solution을 완성해주세요.

 

● 제한 조건

s는 길이 4 이상, 20이하인 문자열입니다.

 

● 입출력 예

 작성 예시

public class Solution {
    public string solution(string phone_number) {
        string answer = "";
        return answer;
    }
}

 문제 풀이

public class Solution {
    public string solution(string phone_number) {
        string answer = "";
        string temp = phone_number.Substring(phone_number.Length - 4, 4);
        
        for(int i = 0; i < phone_number.Length - 4; ++i)
        {
            answer += "*";
        }
        
        return answer += temp;
    }
}

'코딩 테스트 > 프로그래머스' 카테고리의 다른 글

행렬의 덧셈문제  (0) 2021.06.20
제일 작은 수 제거하기  (0) 2021.06.18
직사각형 별찍기  (0) 2021.06.16
약수의 합  (0) 2021.06.15
문자열 다루기 기본  (0) 2021.06.14