반응형
핸드폰 번호 가리기
https://programmers.co.kr/learn/courses/30/lessons/12948
코딩테스트 연습 - 핸드폰 번호 가리기
프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다. 전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자
programmers.co.kr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
using namespace std; | |
string solution(string phone_number) { | |
string answer = ""; | |
int max = phone_number.size() - 4; | |
for (int i = 0; i < max; ++i) | |
{ | |
answer += "*"; | |
} | |
for (int i = max; i < phone_number.size(); ++i) | |
{ | |
answer += phone_number.at(i); | |
} | |
return answer; | |
} |
반응형
'자료구조 와 알고리즘 > 프로그래머스' 카테고리의 다른 글
평균 구하기 (0) | 2022.05.08 |
---|---|
하샤드 수 (0) | 2022.05.08 |
행렬의 덧셈 (0) | 2022.05.08 |
x만큼 간격이 있는 n개의 숫자 (0) | 2022.05.08 |
직사각형 별찍기 (0) | 2022.05.08 |