티스토리 뷰
728x90
문제 설명
프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다.
전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부 *으로 가린 문자열을 리턴하는 함수, solution을 완성해주세요.
제한 조건
- s는 길이 4 이상, 20 이하인 문자열입니다.
입출력 예
phone_number | return |
"01033334444" | "*******4444" |
"027778888" | "*****8888" |
코드
#include <string>
#include <vector>
using namespace std;
string solution(string phone_number) {
string answer = "";
int i;
for (i=0; i < phone_number.size() - 4; i++)
{
answer.push_back('*');
}
for (i = phone_number.size() - 4; i < phone_number.size(); i++)
{
answer.push_back(phone_number[i]);
}
return answer;
}
링크
programmers.co.kr/learn/courses/30/lessons/12948
코딩테스트 연습 - 핸드폰 번호 가리기
프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다. 전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자
programmers.co.kr
inbdni/Programmers
Contribute to inbdni/Programmers development by creating an account on GitHub.
github.com
728x90
'Coding Test > Programmers' 카테고리의 다른 글
[프로그래머스] 124 나라의 숫자 / C++ (0) | 2020.12.26 |
---|---|
[프로그래머스] 행렬의 덧셈 / C++ (0) | 2020.12.26 |
[프로그래머스] 하샤드 수 / C++ (0) | 2020.12.26 |
[프로그래머스] 평균 구하기 / C++ (0) | 2020.12.26 |
[프로그래머스] 키패드 누르기 / C++ (0) | 2020.12.26 |