※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 16360번 문제인 Go Latin이다.
문제는 아래 링크를 확인하자.
https://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
문자열의 끝에 따라서 단어의 끝을 바꿔 출력해주는 문제이다.
문제에서 주어지는 문자열의 길이는 모두 3 이상이므로, 마지막 글자(또는 마지막에서 두번째 글자)가 무엇인지를 확인 후 문자열의 마지막을 바꿔 출력해주자.
표 아래에도 조건("-us")이 하나 더 있으니 놓치지 말고 구현하자.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T; cin >> T;
while (T--) {
string s; cin >> s;
int slen = s.length();
string sub1 = s.substr(slen - 1, 1), sub2 = s.substr(slen - 2, 2);
if (sub1 == "a") cout << s << "s\n";
else if (sub1 == "i" || sub1 == "y") cout << s.substr(0, slen - 1) << "ios\n";
else if (sub1 == "l") cout << s << "es\n";
else if (sub1 == "n") cout << s.substr(0, slen - 1) << "anes\n";
else if (sub2 == "ne") cout << s.substr(0, slen - 2) << "anes\n";
else if (sub1 == "o") cout << s << "s\n";
else if (sub1 == "r") cout << s << "es\n";
else if (sub1 == "t") cout << s << "as\n";
else if (sub1 == "u") cout << s << "s\n";
else if (sub1 == "v") cout << s << "es\n";
else if (sub1 == "w") cout << s << "as\n";
else cout << s << "us\n";
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 15733 // C++] 나는 누구인가 (0) | 2022.06.22 |
---|---|
[BOJ 24928 // C++] Magical Runes (0) | 2022.06.21 |
[BOJ 5585 // C++] 거스름돈 (0) | 2022.06.19 |
[BOJ 5588 // C++] 별자리 찾기 (0) | 2022.06.19 |
[BOJ 14731 // C++] 謎紛芥索紀 (Large) (0) | 2022.06.19 |