[백준/BOJ] 백준 16360번 : Go Latin

2020. 11. 5. 22:47알고리즘 문제풀이

www.acmicpc.net/problem/16360

 

16360번: Go Latin

Your program is to read from standard input. The input starts with a line containing an integer, n (1 ≤ n ≤ 20), where n is the number of English words. In the following n lines, each line contains an English word. Words use only lowercase alphabet let

www.acmicpc.net

표에 표시된 규칙으로 글자를 나타내고, 표에 표시되지 않은 경우일 때는 끝에 "us"를 붙인다.

 

코드

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int n;
string input;
string result;

int main()
{
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		result = "";
		cin >> input;

		//표에 표시된 규칙으로 바꾼다
		if (input.substr(input.size() - 1, 1) == "a")
		{
			result = input.substr(0, input.size() - 1);
			result += "as";
		}

		else if (input.substr(input.size() - 1, 1) == "i")
		{
			result = input.substr(0, input.size() - 1);
			result += "ios";
		}

		else if (input.substr(input.size() - 1, 1) == "y")
		{
			result = input.substr(0, input.size() - 1);
			result += "ios";
		}

		else if (input.substr(input.size() - 1, 1) == "l")
		{
			result = input.substr(0, input.size() - 1);
			result += "les";
		}

		else if (input.substr(input.size() - 1, 1) == "n")
		{
			result = input.substr(0, input.size() - 1);
			result += "anes";
		}

		else if (input.substr(input.size() - 2, 2) == "ne")
		{
			result = input.substr(0, input.size() - 2);
			result += "anes";
		}

		else if (input.substr(input.size() - 1, 1) == "o")
		{
			result = input.substr(0, input.size() - 1);
			result += "os";
		}

		else if (input.substr(input.size() - 1, 1) == "r")
		{
			result = input.substr(0, input.size() - 1);
			result += "res";
		}

		else if (input.substr(input.size() - 1, 1) == "t")
		{
			result = input.substr(0, input.size() - 1);
			result += "tas";
		}

		else if (input.substr(input.size() - 1, 1) == "u")
		{
			result = input.substr(0, input.size() - 1);
			result += "us";
		}

		else if (input.substr(input.size() - 1, 1) == "v")
		{
			result = input.substr(0, input.size() - 1);
			result += "ves";
		}

		else if (input.substr(input.size() - 1, 1) == "w")
		{
			result = input.substr(0, input.size() - 1);
			result += "was";
		}

		//표에 나타나지 않은 경우일때
		else
		{
			result = input + "us";
		}

		cout << result << "\n";

	}

	return 0;
}