새발블로그

[프로그래머스/C++] 대소문자 바꿔서 출력하기 본문

Problem Solving/Programmers

[프로그래머스/C++] 대소문자 바꿔서 출력하기

EUG 2024. 3. 4. 15:45

문제

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

풀이방법

char& 는 참초(reference) 타입을 나타냄

isupper : 대문자인지 판별

islower : 소문자인지 판별

toupper : 소문자 -> 대문자

tolower: 대문자 -> 소문자

풀이

 

#include <iostream>
#include <string>

using namespace std;

int main(void) 
{
    string str;
    cin >> str;
    
    for (char& c : str) 
    {
        if (isupper(c)) 
        {
            c = tolower(c);
        } 
        else if (islower(c)) 
        {
            c = toupper(c);
        }
    }
    cout << str << endl;
    return 0;
}