※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 27058번 문제인 Message Decowding이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/27058
27058번: Message Decowding
The cows are thrilled because they've just learned about encrypting messages. They think they will be able to use secret messages to plot meetings with cows on other farms. Cows are not known for their intelligence. Their encryption method is nothing like
www.acmicpc.net
각 문자가 소문자일 때의 대응과 대문자일 때의 대응을 따로 저장하고, 복호화할 각 문자가 대문자인지 소문자인지 둘다 아닌지의 경우를 나누어 문제를 해결하자.
toupper, tolower 등의 함수를 이용하면 구현을 간편하게 할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
string s;
string upper, lower;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
getline(cin, upper);
for (auto& l : upper) l = toupper(l);
lower = upper;
for (auto& l : lower) l = tolower(l);
getline(cin, s);
for (auto& l : s) {
if ('A' <= l && l <= 'Z') cout << upper[l - 'A'];
else if ('a' <= l && l <= 'z') cout << lower[l - 'a'];
else cout << l;
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 5358 // C++] Football (0) | 2023.01.07 |
---|---|
[BOJ 24366 // C++] КЛЕТКИ (0) | 2023.01.07 |
[BOJ 5753 // C++] Pascal Library (0) | 2023.01.07 |
[BOJ 23365 // C++] Buffered Buffet (1) | 2023.01.06 |
[BOJ 18813 // C++] Divisionals Spelling (1) | 2023.01.06 |