티스토리 뷰
#include <string>
#include <stdio.h>
#include <algorithm>
using namespace std;
string solution(string new_id) {
int i, end_count = 0;
string answer = new_id;
for (i = 0; i < answer.length(); i++) {
if (answer[i] >= 65 && answer[i] <= 90) //1
answer[i] += 32;
}
printf("1. 소문자로 치환 결과: %s \n", answer.c_str());
for (i = 0; i < answer.length(); i++) { //2
if ((answer[i] >= 'a' && answer[i] <= 'z') || (answer[i] >= '0' && answer[i] <= '9')
|| answer[i] == '-' || answer[i] == '_' || answer[i] == '.') {
continue;
}
else {
answer.erase(i, 1);
i--;
}
}
printf("2. 다른 문자 제거 결과: %s \n", answer.c_str());
for (i = 1; i < answer.length(); i++) { //3
if (answer[i] == '.' && answer[i - 1] == '.') {
answer.erase(i, 1);
i--;
}
}
printf("3. 다른 문자 제거 결과: %s \n", answer.c_str());
if (answer[0] == '.') { //4
answer.erase(0, 1);
}
else if (answer[answer.length() - 1] == 44) {
answer.erase(answer.length() - 1);
}
printf("4. 다른 문자 제거 결과: %s \n", answer.c_str());
if (answer.length() == 0)
answer += "a";
printf("5. 다른 문자 제거 결과: %s \n", answer.c_str());
if (answer.length() >= 16) {
answer.erase(15, answer.length());
}
printf("6-1. 다른 문자 제거 결과: %s \n", answer.c_str());
if (answer[answer.length() - 1] == '.')
answer.erase(answer.length() - 1, 1);
printf("6-2. 다른 문자 제거 결과: %s \n", answer.c_str());
if (answer.length() <= 2) {
while (answer.length() != 3) {
answer += answer[answer.length() - 1];
}
}
return answer;
'algorithm' 카테고리의 다른 글
[프로그래머스] 다음 큰 숫자 (C++) (0) | 2022.09.26 |
---|---|
[프로그래머스] 캐시 (C++) (1) | 2022.09.25 |
[프로그래머스] 뉴스 클러스터링 C++ (1) | 2022.09.23 |
[프로그래머스] 영어 끝말잇기 (C++) (0) | 2022.09.22 |
[프로그래머스] 베스트 앨범 (1) | 2022.09.21 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- PostgreSQL
- OS
- AWS
- 응답코드
- 운영체제
- 시스템콜
- Auditing
- springboot
- RDS
- 정수삼각형
- dp
- Android
- 프로그래머스
- 머신러닝
- 최고의집합
- xv6
- 괄호회전하기
- PasswordEncoder
- interrupt
- qemu
- ubuntu
- 최솟값구하기
- 실패율
- 영어끝말잇기
- 백준
- 다음큰숫자
- 이진변환반복하기
- 프리티어
- 우분투설치
- 뉴스클러스터링
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함