[Algorithm] 핸드폰 번호 가리기

2024. 12. 13. 10:07·Algorithm/Practice

문제 설명

프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다. 

전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부 *으로 가린 문자열을 리턴하는 함수, solution을 완성해주세요.

 

문제 유형

  • 문자열 변환

 

의사코드

  1. [반복문] 입력받은 문자열의 길이 - 4 만큼 반복한다.
    1. 현재 인덱스의 문자열 요소를 '*'로 대입한다.
  2. 결과값을 반환한다.

 

코드 작성

string solution(string phone_number) {
    for (int idx = 0; idx < phone_number.size() - 4; idx++)
    {
        phone_number[idx] = '*';
    }
    
    return phone_number;
}

'Algorithm > Practice' 카테고리의 다른 글

[Algorithm] 서울에서 김서방 찾기  (0) 2024.12.14
[Algorithm] 없는 숫자 더하기  (2) 2024.12.13
[Algorithm] 음양 더하기  (1) 2024.12.13
[Algorithm] 콜라츠 추측  (0) 2024.12.12
[Algorithm] 두 정수 사이의 합  (0) 2024.12.11
'Algorithm/Practice' 카테고리의 다른 글
  • [Algorithm] 서울에서 김서방 찾기
  • [Algorithm] 없는 숫자 더하기
  • [Algorithm] 음양 더하기
  • [Algorithm] 콜라츠 추측
DevColIn
DevColIn
복잡함을 단순하게
  • DevColIn
    심플한 코딩생활
    복잡함을 단순하게
  • 전체
    오늘
    어제
    • 전체보기 (223)
      • Unreal 부트캠프 (49)
        • TIL (34)
        • 사전캠프 (7)
        • 본캠프 (8)
      • Unrael (10)
        • 환경설정 (0)
        • Basic (19)
        • Component (5)
        • GAS (GameplayAbilitySystem) (3)
        • AI (2)
        • Implement (10)
        • UI (1)
        • Error (1)
        • Network (2)
        • Tip (1)
      • Level Design (5)
      • Math (1)
      • Design Pattern (16)
      • Computer Science (2)
        • Network (1)
        • Database (1)
      • Algorithm (79)
        • Basic (4)
        • Practice (74)
      • C++ (4)
        • Basic (4)
      • Tool (0)
      • Game (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 미디어로그
    • 위치로그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    component
    사전캠프
    tsoftobjectptr
    basic
    액터
    AI
    GameplayEffect
    내일배움캠프
    unreal
    unrealengine
    gas
    Implement
    Design Pattern
    디자인 패턴
    디자인패턴
    하드 레퍼런싱
    알고리즘
    Animation
    actor
    Algorithm
    게임동기화
    DesignPattern
    Til
    assetmanager
    소프트 레퍼런신
    퀘스트
    레벨디자인
    c++
    KPT회고
    본캠프
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.2
DevColIn
[Algorithm] 핸드폰 번호 가리기
상단으로

티스토리툴바