Taene's

[백준] 브론즈1-ROT13 C++ 11655번 본문

백준/브론즈

[백준] 브론즈1-ROT13 C++ 11655번

taene_ 2025. 2. 22. 01:25

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;
}