본문 바로가기

Baekjoon/C++

[C++][BOJ/백준] 5358 Football Team

 

 

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;
}