在这里我们将看到一个简单的问题。我们必须在给定列表中找到本质上是回文的所有数字。方法很简单,从列表中取出每个数字并检查它是否是回文,然后打印该数字。
Begin for each element e in arr, do if e is palindrome, then print e end if done End
#include <iostream> #include <cmath> using namespace std; bool isPalindrome(int n){ int reverse = 0, t; t = n; while (t != 0){ reverse = reverse * 10; reverse = reverse + t%10; t = t/10; } return (n == reverse); } int getAllPalindrome(int arr[], int n) { for(int i = 0; i<n; i++){ if(isPalindrome(arr[i])){ cout << arr[i] << " "; } } } int main() { int arr[] = {25, 145, 85, 121, 632, 111, 858, 45}; int n = sizeof(arr) / sizeof(arr[0]); cout << "All palindromes: "; getAllPalindrome(arr, n); }
All palindromes: 121 111 858
以上就是列表中的所有回文数字是什么?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号