PS/CodeUp
CodeUp / String(문자열) / 1295번 / 알파벳 대소문자 변환 / C++
KimMinJun
2020. 9. 29. 22:19
문제 설명
주어지는 문장의 대문자를 소문자로, 소문자를 대문자로 변경하는 프로그램을 작성하라.
입력
한 줄의 공백없는 문장이 입력된다.(최대 길이:1000)
출력
대소문자를 서로 변환한 결과를 출력한다.
입력 예시
CodeChallenge2014withMSP
출력 예시
cODEcHALLENGE2014WITHmsp
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
cin >> str;
for(int i=0; i<str.length(); i++) {
if(str[i]>='A' && str[i]<='Z') {
str[i] = tolower(str[i]);
}
else if(str[i]>='a' && str[i]<='z') {
str[i] = toupper(str[i]);
}
}
cout << str << endl;
}
C++ 에는 string 라이브러리에 편리한 것들이 많다.
tolower()는 소문자로 바꿔주는 함수이고, toupper()는 대문자로 바꿔주는 함수이다.