ここでの問題は、ユーザー入力からの文字列にできないことです。文字列は 7 つあり、そのうち 6 つが数字で、1 つが単語「abba」です。これまでに多くのコードを作成しましたが、プログラムに使用する必要がある 7 つの文字列をテストする方法を見つけるのに苦労しています。
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
bool isNumPalindrome(string str);
int main ()
{
string str;
str = "10", "32", "222", "abba", "444244", "67867876", "123454321";
int userExit;
bool isNum = isNumPalindrome;
if (isNumPalindrome)
{
cout << str << " is a palindrome";
cout << endl;
}
else
{
cout << str << " is not a palindrome";
cout << endl;
}
cout << "Press any key to exit: ";
cin >> userExit;
cout << endl;
return 0;
}
bool isNumPalindrome(string str)
{
int length = str.length();
for (int i = 0; i < length / 2; i++)
if (str[i] != str[length - 1 - i])
return false;
return true;
}
ご覧のとおり、main で関数を実行して return を受け取ってステートメントを出力する方法がよくわかりません。複数の文字列をテストする方法を見つけてから、return ステートメントを使用してcout << str << "
is not a palindrome のようなものを出力する方法を見つける必要があります。";