algorithm
백준 2744번 대소문자 바꾸기
YOU__NAVI
2024. 10. 27. 00:31
https://www.acmicpc.net/problem/2744
아이디어:
1. string 자료형 사용 > for문, 배열처럼 접근 가능
2. ascii코드 값 활용 > 대문자 + 32 = 소문자, 소문자 - 32 = 대문자
// 2744
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
string str;
cin >> str;
for (int i = 0; i < str.size(); i++) {
if ('A' <= str[i] && str[i] <= 'Z') {
str[i] += 32;
}
else if ('a' <= str[i] && str[i] <= 'z') {
str[i] -= 32;
}
}
cout << str;
return 0;
}