728x90
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
문제 풀이
입력받은 문자들을 다음의 조건을 통해 변환해서 출력하는 문제이다.
- 'e'는 'i'로 변환된다.
- 'i'는 'e'로 변환된다.
- 'E'는 'I'로 변환된다.
- 'I'는 'E'로 변환된다.
정답 코드
C++
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define ll long long
int main() {
fast;
string s;
while (1) {
getline(cin, s);
if (cin.eof()) break;
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'e') cout << 'i';
else if (s[i] == 'i') cout << 'e';
else if (s[i] == 'E') cout << 'I';
else if (s[i] == 'I') cout << 'E';
else cout << s[i];
}
cout << "\n";
}
}
python
try:
while True :
s = input()
for i in range(len(s)) :
if s[i] == 'e' : print("i", end = "")
elif s[i] == 'i' : print("e", end = "")
elif s[i] == 'E' : print("I", end = "")
elif s[i] == 'I' : print("E", end = "")
else : print(s[i], end = "")
print()
except:
exit(0)
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 6825 - Body Mass Index [C++/python] (0) | 2023.03.02 |
---|---|
[BOJ/백준] 5524 - 입실 관리 [C++/python] (0) | 2023.03.02 |
[BOJ/백준] 5357 - Dedupe [C++/python] (0) | 2023.03.02 |
[BOJ/백준] 5341 - Pyramids [C++/python] (0) | 2023.03.02 |
[BOJ/백준] 5300 - Fill the Rowboats! [C++/python] (0) | 2023.03.02 |