문제
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
해결방법
while문 안에 getline(cin, str) 함수를 사용하여 입력값이 없을 때 까지 입력받고 문자열을 for문으로 하나씩 보면서 e는 i로, E는 I로, i는 e로, I는 E로 변경 후 출력한다.
코드
#include<iostream>
#include<string>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string str;
while (getline(cin, str)) {
for (int i = 0; i < str.length(); i++) {
if (str[i] == 'e')
str[i] = 'i';
else if (str[i] == 'E')
str[i] = 'I';
else if (str[i] == 'i')
str[i] = 'e';
else if (str[i] == 'I')
str[i] = 'E';
}
cout << str << '\n';
}
return 0;
}'PS > Baekjoon' 카테고리의 다른 글
| [C++] 백준 22155: Простая задача (0) | 2023.05.17 |
|---|---|
| [C++] 백준 27890: 특별한 작은 분수 (1) | 2023.05.16 |
| [C++] 백준 6825: Body Mass Index (0) | 2023.05.14 |
| [C++] 백준 25784: Easy-to-Solve Expressions (0) | 2023.05.13 |
| [C++] 백준 6887: Squares (0) | 2023.05.12 |
댓글