返回列表 發帖

504 迴文數

本帖最後由 陳曜誌 於 2024-12-18 19:22 編輯

1. 題目說明:
請依下列題意進行作答,使輸出值符合題意要求。

2. 設計說明:
請撰寫一程式,讓使用者輸入一正整數,判斷是否為迴文數,若是,請輸出「Yes」;若不是,請輸出「No」。

迴文數:此數的數字按相反的順序重新排列後,所得到的數和原來的數一樣。

提示:若使用 Java 語言答題,請以「JP」開頭命名包含 main 靜態方法的 class,評測系統才能正確評分。

3. 輸入輸出:
輸入說明
一個正整數

輸出說明
判斷是否為迴文數

範例輸入1
14641
範例輸出1
Yes

範例輸入2
25523
範例輸出2
No

本帖隱藏的內容需要回復才可以瀏覽

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int main()
  5. {
  6.     cin>>str;
  7.     int len=str.length();
  8.     for(int i=0;i<len;i++)
  9.     {
  10.         if(str[i]!=str[len-1-i])
  11.         {
  12.             cout<<"No";
  13.             return 0;
  14.         }
  15.     }
  16.     cout<<"Yes";
  17.     return 0;
  18. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int main()
  5. {
  6.     cin>>str;
  7.     int len=str.length();
  8.     for(int i=0;i<len/2;i++)
  9.     {
  10.         if(str[i]!=str[len-i-1])
  11.         {

  12.             cout<<"No";
  13.             return 0;
  14.         }
  15.     }
  16.     cout<<"Yes";
  17.     return 0;
  18. }
複製代碼

TOP

本帖最後由 李彣 於 2024-12-18 19:42 編輯
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int main()
  5. {
  6.     cin>>str;
  7.     int len=str.length();
  8.     for(int i=0;i<len/2;i++)
  9.     {
  10.         if(str[i]!=str[len-1-i])
  11.         {
  12.             cout<<"No";
  13.             return 0;
  14.         }
  15.     }
  16.     cout<<"Yes";
  17.     return 0;
  18. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;

  3. int main()
  4. {
  5.     string str;
  6.     cin>>str;
  7.     int len=str.length();
  8.     for(int i=0;i<len/2;i++ ){
  9.         if(str[i]!=str[len-i-1]){
  10.             cout<<"No"<<endl;
  11.             return 0;
  12.         }
  13.     }
  14.     cout<<"Yes"<<endl;
  15.     return 0;
  16. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int main()
  5. {
  6.     cin>>str;
  7.     int len=str.length();
  8.     for(int i=0;i<len/2;i++){
  9.         if(str[i]!=str[len-i-1])
  10.         {
  11.             cout<<"No";
  12.             return 0;
  13.         }
  14.     }
  15.     cout<<"Yes";
  16.     return 0;
  17. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int main()
  5. {
  6.     cin>>str;
  7.     int len=str.length();
  8.     for(int i=0;i<len/2;i++)
  9.     {
  10.         if(str[i]!=str[len-i-1])
  11.         {
  12.             cout<<"No";
  13.             return 0;
  14.         }
  15.     }
  16.     cout<<"Yes";
  17.     return 0;
  18. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int main()
  5. {
  6.     cin>>str;
  7.     int len=str.length();
  8.     for(int i=0;i<len;i++)
  9.     {
  10.        if(str[i]!=str[len-1-i])
  11.        {
  12.            cout<<"No";
  13.            return 0;
  14.        }
  15.     }
  16.     cout<<"Yes";
  17.     return 0;
  18. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str;
  4. int main()
  5. {
  6.     cin>>str;
  7.     int len=str.length();
  8.     for(int i=0;i<len;i++)
  9.     {
  10.         if(str[i]!=str[len-i-1])
  11.         {
  12.             cout<<"No";
  13.             return 0;
  14.         }
  15.     }
  16.     cout<<"Yes";
  17.     return 0;
  18. }
複製代碼

TOP

返回列表