Add FZOI Codes

This commit is contained in:
2024-06-26 22:14:00 +08:00
parent 8f564ca60e
commit b80791cfad
49 changed files with 1653 additions and 0 deletions

33
FZOI/回文数个数.cpp Normal file
View 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;
}