티스토리 뷰

문제 설명

#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;
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
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
글 보관함