Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // 定義 isPalindrome 函數
- void isPalindrome(string word) ;
- int main()
- {
- string word;
- cin >> word; // 正確讀取字串
- isPalindrome(word); // 調用 isPalindrome 函數
- return 0;
- }
- void isPalindrome(string word)
- {
- int length = word.length();
- bool isPalin = true;
- for (int i = 0; i < length / 2; i++)
- {
- if (word[i] != word[length - 1 - i])
- {
- isPalin = false; // 若找到不匹配的字符,則非迴文
- break;
- }
- }
- if (isPalin)
- {
- cout << "yes";
- }
- else
- {
- cout << "no";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement