Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Dijkstra
- set
- 참고 문헌 : MACHINE LEARNING 기계학습 _ 오일석
- 문자열
- 코딩테스트연습
- 코테준비
- 알고리즘
- substr
- 다익스트라
- 플로이드와샬
- 시스템콜
- 동적계획법
- dfs
- unordered_map
- String
- MySQL
- 다이나믹프로그래밍
- sql고득점kit
- 정렬
- vector
- 스택
- MAP
- 우선순위큐
- 리시프
- 프로그래머스
- C++
- 코테
- 백준
- 최대공약수
- DP
Archives
- Today
- Total
YeJin's Footsteps
신규 아이디 추천 본문
문제 링크
programmers.co.kr/learn/courses/30/lessons/72410
코딩테스트 연습 - 신규 아이디 추천
카카오에 입사한 신입 개발자 네오는 "카카오계정개발팀"에 배치되어, 카카오 서비스에 가입하는 유저들의 아이디를 생성하는 업무를 담당하게 되었습니다. "네오"에게 주어진 첫 업무는 새로
programmers.co.kr
문제 풀이 코드
#include <string>
#include <vector>
#include <iostream>
#include <cctype>
using namespace std;
string solution(string new_id) {
//1단계
for(int i=0; i<new_id.length(); i++){
if(isupper(new_id[i])){
new_id[i]=tolower(new_id[i]);
}
}
//2단계
string tmp="";
for(int i=0; i<new_id.length(); i++){
if(!isdigit(new_id[i])&&!isalpha(new_id[i])){
if(new_id[i]=='.'||new_id[i]=='-'||new_id[i]=='_') tmp+=new_id[i];
else{
continue;
}
}
else{tmp+=new_id[i];}
}
new_id=tmp; tmp="";
//3단계
int cntp=0;
for(int i=0; i<new_id.length(); i++){
if(new_id[i]=='.') {
cntp++;
if(cntp>=2){
continue;
}
else{
tmp+=new_id[i];
}
}
else{
cntp=0;
tmp+=new_id[i];
}
}
new_id=tmp; tmp="";
//4단계
if(new_id[0]=='.') new_id.erase(0,1);
if(new_id[new_id.size()-1]=='.') new_id.erase(new_id.size()-1,1);
//5단계
if(new_id.size()==0){
new_id="a";
}
//6단계
if(new_id.size()>=16){
for(int i=0; i<15; i++){
tmp+=new_id[i];
}
new_id=tmp;
}
if(new_id[new_id.size()-1]=='.') new_id.erase(new_id.size()-1,1);
//7단계
if(new_id.size()<=2){
char lastc=new_id[new_id.size()-1];
while(new_id.size()<3){
new_id+=lastc;
}
}
string answer = new_id;
return answer;
}
'Computer Science & Engineering > 알고리즘' 카테고리의 다른 글
가장 큰 수 (0) | 2021.07.01 |
---|---|
불량사용자 (0) | 2021.05.07 |
튜플 (0) | 2021.05.02 |
크레인 인형 뽑기 게임 (0) | 2021.05.02 |
완주하지 못한 선수 (0) | 2021.05.02 |
Comments