Taene's
[백준] 브론즈1-ROT13 C++ 11655번 본문
https://www.acmicpc.net/problem/11655
// 알파벳 개수=26, 'A'=65, 'a'=97
#include <iostream>
#include <string>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s, answer;
getline(cin, s);
for (int i = 0; i < s.size(); i++)
{
if (s[i] >= 'A' && s[i] <= 'Z')
{
int temp = (s[i] + 13);
if (temp > 'Z') temp -= 26;
answer += (char)temp;
}
else if (s[i] >= 'a' && s[i] <= 'z')
{
int temp = (s[i] + 13);
if (temp > 'z') temp -= 26;
answer += (char)temp;
}
else
answer += s[i];
}
cout << answer;
return 0;
}
// 2회차 풀이
#include <iostream>
#include <string>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
while (getline(cin, s))
{
for (int i = 0; i < s.size(); i++)
{
if (s[i] >= 'A' && s[i] <= 'Z')
{
int k = (int)(s[i] + 13);
if (k > 'Z')
k -= 26;
s[i] = (char)k;
}
else if (s[i] >= 'a' && s[i] <= 'z')
{
int k = (int)(s[i] + 13);
if (k > 'z')
k -= 26;
s[i] = (char)k;
}
}
cout << s;
return 0;
}
return 0;
}
'백준 > 브론즈' 카테고리의 다른 글
[백준] 브론즈3-팰린드롬인지 확인하기 C++ 10988번 (0) | 2025.03.18 |
---|---|
[백준] 브론즈2-트럭 주차 C++ 2979번 (0) | 2025.02.21 |
[백준] 브론즈4-알파벳 개수 C++ 10808번 (0) | 2025.02.21 |
[백준] 브론즈1-일곱 난쟁이 C++ 2309번 (0) | 2025.02.21 |
[백준] 브론즈1-평균 C++ 1546번 (0) | 2024.02.26 |