※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 5358번 문제인 Football이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/5358
5358번: Football Team
Print the same list of names with every ‘i’ replaced with an ‘e’, every ‘e’ replaced with an ‘i’, every ‘I’ replaced with an ‘E’, and every ‘E’ replaced with an ‘I’.
www.acmicpc.net
주어진 각 문자열에서 모든 'i'를 'e'로, 모든 'e'를 'i'로, 모든 'E'를 'I'로, 모든 'I'를 'E'로 바꿔 출력해주자.
각 문자 하나하나를 보면서 그 문자가 i, e, E, I인지를 확인해 출력해야하는 문자 하나를 출력하는 것을 반복하면 구현을 간단하게 할 수 있다.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
string s;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
while (getline(cin, s)) {
for (auto& l : s) {
if (l == 'i') cout << 'e';
else if (l == 'e') cout << 'i';
else if (l == 'I') cout << 'E';
else if (l == 'E') cout << 'I';
else cout << l;
}
cout << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 3554 // C++] Enigmatic Device (0) | 2023.01.07 |
---|---|
[BOJ 24366 // C++] КЛЕТКИ (0) | 2023.01.07 |
[BOJ 27058 // C++] Message Decowding (0) | 2023.01.07 |
[BOJ 5753 // C++] Pascal Library (0) | 2023.01.07 |
[BOJ 23365 // C++] Buffered Buffet (1) | 2023.01.06 |