'commit'
This commit is contained in:
37
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao14STEMA202303/BC3.cpp
Normal file
37
TangDou/LanQiaoBei/ZhongGaoJi/LanQiao14STEMA202303/BC3.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
int check(int x) {
|
||||
// 转9进制
|
||||
string res;
|
||||
while (x) {
|
||||
int a = x % 9;
|
||||
res += to_string(a);
|
||||
x /= 9;
|
||||
}
|
||||
// 每个数位都是奇数
|
||||
for (int i = 0; i < res.size(); i++)
|
||||
if ((res[i] - '0') % 2 == 0) return 0;
|
||||
|
||||
// 判断转完的9进制是不是回文数
|
||||
// 方法1
|
||||
// string str = res;
|
||||
// reverse(str.begin(), str.end());
|
||||
// return str == res;
|
||||
|
||||
// 方法2
|
||||
for (int i = 0; i < (res.size() + 1) / 2; i++)
|
||||
if (res[i] != res[res.size() - 1 - i]) return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
int main() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
int res = 0;
|
||||
for (int i = n; i <= m; i++) res += check(i);
|
||||
|
||||
cout << res << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user