프로그래머스_C#/Level_1
[프로그래머스 C#] 핸드폰 번호 가리기
최애뎡
2021. 6. 4. 23:37
728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/12948
코딩테스트 연습 - 핸드폰 번호 가리기
프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다. 전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자
programmers.co.kr
using System.Text;
public class Solution {
public string solution(string phone_number) {
StringBuilder answer = new StringBuilder();
for (int i = 0; i < phone_number.Length; i++)
{
char num = i < phone_number.Length - 4 ? '*' : phone_number[i];
answer.Append(num);
}
return answer.ToString();
}
}
StringBuilder의 경우 여기선 굳이 사용하지 않아도 되지만 몇만 번 이상씩 Text를 더해야 할 경우 무조건 적으로 사용해야 한다. StringBuilder와 Text += Text에 대해선 구글링에 정말 수많은 자료가!
쉽고 간단한 문제이지만 더 깊게 생각해서 풀기
반응형