我試圖找到一個在互聯網上的解決方案,但無法找到類似的東西。我使用strcpy和迭代在C++中創建迴文函數,所有工作都正常,但是strcpy部分。我不知道如何解決它或使用其他替代方法。謝謝。Palindrome C++(strcpy)
#include <iostream>
#include <cstring>
using namespace std;
void palindrom(char[]);
int main()
{
char binput[100];
cout << "Hello please enter your word here: " << endl;
cin >> binput;
palindrom(binput);
system("pause");
return 1;
}
void palindrom(char binput[])
{
int max= strlen(binput);
char cinput[100];
char dinput[100];
for (int i=max, n=0; i>=0, n<=max; i--, n++)
strcpy(dinput[n],binput[i]);
cout << dinput << endl;
if (strcmp(binput,dinput)==true)
cout << "Is palindrome " << endl;
else
cout << "Is not " << endl;
}
* 「我使用的strcpy」 * - 使用'的std :: string'。 –
你需要它在C++或是Java好嗎? –
@JürgenK。我需要它在C++謝謝 –