๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜/Programmers

[PGS] Lv.0 (์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ) 12์ผ์ฐจ ๋ฌธ์ œ

728x90

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๋ ˆ๋ฒจ 0 ๋ฌธ์ž์—ด, ์ •๋ ฌ, ์‚ฌ์น™์—ฐ์‚ฐ, ์ˆ˜ํ•™

โœ๐Ÿป ๋ฌธ์ž์—ด ๋Œ€์ฒด → my_string.replace(j,1,""); : ์ธ๋ฑ์Šค j์˜ ์›์†Œ๋ถ€ํ„ฐ ๊ธธ์ด 1๋งŒํผ์„ “”๋กœ ๋Œ€์ฒด

โœ๐Ÿป ๋ฌธ์ž ๋‚ด์šฉ์ด ์ˆซ์ž์ธ์ง€? → isdigit(c) : ์ˆซ์ž๋ฉด ์–‘์ˆ˜, ์•„๋‹ˆ๋ฉด 0์„ ๋ฆฌํ„ดํ•จ

โœ๐Ÿป vector to set → set<int> s(v.begin(), v.end());

โœ๐Ÿป set to vector → vector<int> v(s.begin(), s.end());

 

 

๋ชจ์Œ ์ œ๊ฑฐ

string solution(string my_string) {
    string m = "aeiou";
    for(int i=0; i<5; ++i){
        for(int j=0; j<my_string.length(); ++j){
            if(my_string[j]==m[i]) {
                i--;
                my_string.replace(j,1,"");
            }
        }
    }
    return my_string;
}

๋ฌธ์ž์—ด ์ •๋ ฌํ•˜๊ธฐ (1)

vector<int> solution(string my_string) {
    vector<int> answer;
    for(int i=0; i<my_string.size(); ++i){
        if(isdigit(my_string[i])){
            answer.push_back(my_string[i]-'0');
        }
    }
    sort(answer.begin(), answer.end());
    return answer;
}

์ˆจ์–ด์žˆ๋Š” ์ˆซ์ž์˜ ๋ง์…ˆ (1)

int solution(string my_string) {
    int answer = 0;
    for(auto i : my_string){
        if(isdigit(i)) answer += (i-'0');
    }
    return answer;
}

์†Œ์ธ์ˆ˜๋ถ„ํ•ด

vector<int> solution(int n) {
    vector<int> answer;
    for(int i=2; i<=n; ++i){
        if(n%i==0){
            n /= i;
            answer.push_back(i);
            i=1;
        }
        if(n==1) break;
    }
    sort(answer.begin(), answer.end());
    set<int> s(answer.begin(), answer.end());
    vector<int> v(s.begin(), s.end());
    return v;
}

 

728x90