Baekjoon Online Judge
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
[문제]
The PLU football coach must submit to the NCAA officials the names of all players that will be competing in NCAA Division II championship game. Unfortunately his computer keyboard malfunctioned and interchanged the letters ‘i’ and ‘e’. Your job is to write a program that will read all the names and print the names with the correct spelling.
[입력]
The file contains a list of names, and each name will be on a separate line.
[출력]
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’.
[코드]
#include <iostream>
#include <string>
using namespace std;
int main()
{
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';
}
return 0;
}
'Baekjoon > C++' 카테고리의 다른 글
[C++][BOJ/백준] 2985 세 수 (0) | 2024.04.15 |
---|---|
[C++][BOJ/백준] 24079 移動 (Moving) (0) | 2024.04.14 |
[C++][BOJ/백준] 13163 닉네임에 갓 붙이기 (0) | 2024.04.12 |
[C++][BOJ/백준] 2711 오타맨 고창영 (0) | 2024.04.11 |
[C++][BOJ/백준] 30402 감마선을 맞은 컴퓨터 (0) | 2024.04.08 |