mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-07-07 18:06:58 +08:00
Add FZOI Codes
This commit is contained in:
33
FZOI/回文数个数.cpp
Normal file
33
FZOI/回文数个数.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool isPalindrome(int num) {
|
||||
string str = to_string(num);
|
||||
int left = 0, right = str.length() - 1;
|
||||
while (left < right) {
|
||||
if (str[left] != str[right]) {
|
||||
return false;
|
||||
}
|
||||
left++;
|
||||
right--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
int count = 0;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (isPalindrome(i)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << count << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user