[프로그래머스/C++]Lv.0 - 대문자와 소문자

YH J·2023년 4월 17일
0

프로그래머스

목록 보기
20/168

문제 링크

https://school.programmers.co.kr/learn/courses/30/lessons/120893

내 풀이

'Z'를 기준으로 대문자 소문자를 판별하여 tolower, toupper함수 사용하여 바꿔준다.

내 코드

#include <string>
#include <vector>

using namespace std;

string solution(string my_string) {
    string answer = "";
    
    for(auto& s : my_string)
    {
        if(s <= 'Z')
            s = tolower(s);
        else
            s = toupper(s);
    }
    return my_string;
}

다른 사람의 풀이

#include <string>
#include <vector>

using namespace std;

string solution(string my_string) {
    for(auto& v : my_string)
    {
        if(islower(v))
        {
            v = toupper(v);
        }
        else 
        {
            v = tolower(v);
        }
    }
    return my_string;
}

다른 사람의 풀이 해석

islower함수 사용하여 대소문자 판별

profile
게임 개발자 지망생

0개의 댓글