0
這裏是我的代碼。不「工作」,並繼續說,他們是迴文如果纏CIN人物的名單仍然說,他們是正確的。不起作用的字符列表如下:在迴文程序特定的字符不要工作
單引號,雙引號,逗號,句點,正斜槓,反斜槓,破折號,感嘆號,@符號,#符號,$符號,%符號,^符號,&符號,符號*(星號),等於符號,符號+
int main()
{
int k = 1;
int i;
int length, halflength;
int yesno = 1;
char string [81];
char end[81] = "END";
while (k = 1)
{
cout << "Please enter a string of characters. " << endl;
cout << "Enter \"END\" in all caps to exit the program." << endl;
cin.getline(string, 81);
if (strcmp(string, "END") == 0)
{
return 0;
}
length = strlen(string);
halflength = length/2;
for (i = 0; i < halflength; i++)
{
if (string[i] != string[length - i - 1]) // comparing
yesno = 0;
break;
}
if (yesno) {
cout << "You have successfully entered a palindrome." << endl;
}
else
{
cout << "You have not entered a palindrome." << endl;
return main();
}
}
}
我不確定如何解決這個問題,作爲一個迴文不僅可以是字母順序,但字符序列。如果有一種比較線條的更簡單的方法,那麼我會很感激這種幫助,因爲我在這方面花了一些時間而感到沮喪。