영어 알파벳으로 이루어진 문자열 str이 주어집니다. 각 알파벳을 대문자는 소문자로 소문자는 대문자로 변환해서 출력하는 코드를 작성해 보세요.
#include <iostream>
#include <string>
using namespace std;
int main() {
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;
}
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void) {
string str;
cin >> str;
for(char ch : str)
{
if(isupper(ch))
cout << (char)tolower(ch);
else
cout << (char)toupper(ch);
}
return 0;
}
#include <algorithm>