“蓝桥杯”练习系统 - 基础练习 - 回文数

思路:

取每一位, 第一位和第四位相同, 第二位和第三位相同即回文数.

 

 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 }

 

posted @ 2020-02-01 17:02  域Anton  阅读(164)  评论(0)    收藏  举报