Advertisement
junsangtutor

zerojudge a022

Dec 2nd, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // 定義 isPalindrome 函數
  5. void isPalindrome(string word) ;
  6.  
  7. int main()
  8. {
  9.     string word;
  10.     cin >> word;  // 正確讀取字串
  11.     isPalindrome(word);  // 調用 isPalindrome 函數
  12.     return 0;
  13. }
  14.  
  15. void isPalindrome(string word)
  16. {
  17.     int length = word.length();
  18.     bool isPalin = true;
  19.  
  20.     for (int i = 0; i < length / 2; i++)
  21.     {
  22.         if (word[i] != word[length - 1 - i])
  23.         {
  24.             isPalin = false; // 若找到不匹配的字符,則非迴文
  25.             break;
  26.         }
  27.     }
  28.  
  29.     if (isPalin)
  30.     {
  31.         cout << "yes";
  32.     }
  33.     else
  34.     {
  35.         cout << "no";
  36.     }
  37. }
  38.  
  39.  
Tags: ZEROJUDGE a022
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement