새발블로그
[프로그래머스/C++] 대소문자 바꿔서 출력하기 본문
문제
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;
}
'Problem Solving > Programmers' 카테고리의 다른 글
| [프로그래머스/C++] 수 조작하기 1 (0) | 2024.03.06 |
|---|---|
| [프로그래머스/C++] 주사위 게임 2 (0) | 2024.03.05 |
| [프로그래머스/C++] 두 수의 연산값 비교하기 (0) | 2024.03.04 |
| [프로그래머스/C++] 문자열 돌리기 (0) | 2024.03.04 |
| [프로그래머스/C++] 더 크게 합치기 (0) | 2024.03.04 |