这道题就是一道循环判断题。
定义 从 到 ,然后判断 的首位是否和末位相等,如果相等,就把答案变量加 。
注意事项:
这题求首位是一个重点,我通过使用 存储 ,再定义变量存储 ,这样就行了。
#include<bits/stdc++.h>
#define int long long
using namespace std;
int l,r;
int ans;
signed main(){
ios::sync_with_stdio(false);
cin>>l>>r;
for(int i = l;i<=r;i++){
int p = log10(i);
int pp = pow(10,p);
if(i/pp == i%10){
ans++;
}
}
cout<<ans;
return 0;
}