자격증/COS Pro
COSPro 2급 C++] 1차 문제8) 팰린드롬 판단하기 - C++
파아란기쁨1
2022. 7. 12. 18:42
반응형


#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool solution(string sentence) {
string alphas = "";
for (char ch : sentence) {
if (ch != '.' && ch != ' ') alphas += ch;
}
int len = alphas.size();
for (int i = 0; i < len / 2; i++) {
if (alphas[i] != alphas[len - 1 - i]) return false;
}
return true;
}
// 아래는 테스트케이스 출력을 해보기 위한 main 함수입니다.
// 아래의 main 함수에서는 틀린 부분 없습니다.
// solution 함수를 수정하세요.
int main() {
string sentence1 = "never odd or even.";
bool ret1 = solution(sentence1);
// Press Run button to receive output.
cout << "solution 함수의 반환 값은 " << (ret1 == true ? "true" : "false") << " 입니다." << endl;
string sentence2 = "palindrome";
bool ret2 = solution(sentence2);
// Press Run button to receive output.
cout << "solution 함수의 반환 값은 " << (ret2 == true ? "true" : "false") << " 입니다." << endl;
}반응형