C++ 回文数统计 - 区间内回文数数量
#include
using namespace std;
bool isPalindrome(int num) { string str = to_string(num); int i = 0, j = str.length() - 1; while (i < j) { if (str[i] != str[j]) { return false; } i++; j--; } return true; }
int countPalindromes(int L, int R) { int count = 0; for (int i = L; i <= R; i++) { if (isPalindrome(i)) { count++; } } return count; }
int main() { int L, R; cin >> L >> R; int count = countPalindromes(L, R); cout << count << endl; return 0; }
原文地址: https://www.cveoy.top/t/topic/qoUD 著作权归作者所有。请勿转载和采集!