思路:
取每一位, 第一位和第四位相同, 第二位和第三位相同即回文数.
1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 ios::sync_with_stdio(false); 7 cin.tie(0); 8 9 for (int i = 1001; i <= 9999; i++) { 10 int a = i % 10; 11 int b = i / 10 % 10; 12 int c = i / 100 % 10; 13 int d = i / 1000; 14 if (a == d && b == c) 15 cout << i << endl; 16 } 17 18 return 0; 19 }
原文:https://www.cnblogs.com/AntonLiu/p/12249070.html