그래서 T've는 palindrome 프로그램을 하나의 단어 palindrome을 확인하는 백만 가지 예제를 발견했습니다.Word palindrome program by word
하지만 단어 하나 하나를 문장으로 예를 들어 설명하는 데 도움이 필요합니다. 삼키기를 할 수 있지만 감옥을 삼킬 수는 없습니까? "라는 단어가 단어 회문으로 사용됩니다. 책이 준 코드는이
// FILE: pal.cxx
// Program to test whether an input line is a palindrome. Spaces,
// punctuation, and the difference between upper- and lowercase are ignored.
#include <cassert> // Provides assert
#include <cctype> // Provides isalpha, toupper
#include <cstdlib> // Provides EXIT_SUCCESS
#include <iostream> // Provides cout, cin, peek
#include <queue> // Provides the queue template class
#include <stack> // Provides the stack template class
using namespace std;
int main()
{
queue<char> q;
stack<char> s;
char letter;
queue<char>::size_type mismatches = 0; // Mismatches between queue and stack
cout << "Enter a line and I will see if it's a palindrome:" << endl;
while (cin.peek() != '\n')
{
cin >> letter;
if (isalpha(letter))
{
q.push(toupper(letter));
s.push(toupper(letter));
}
}
while ((!q.empty()) && (!s.empty()))
{
if (q.front() != s.top())
++mismatches;
q.pop();
s.pop();
}
if (mismatches == 0)
cout << "That is a palindrome." << endl;
else
cout << "That is not a palindrome." << endl;
return EXIT_SUCCESS;
}
아직 시작점이 아닌가요? –
음 ... 뭐가 문제입니까? – Asha
@Asha 단어 palindrome으로 단어를하는 법을 알아야 할 필요가 있다고 생각할 수있는 유일한 방법은 문자열을 사용하는 것이지만 문자열 조각을 조각으로 튀어 나오게하는 방법을 모른다는 것입니다. – user2206227