Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream> // file stream
- using namespace std;
- int oglindit(int z);
- int estePalindrom(int n);
- int main()
- {
- int n, a,b;
- ifstream fin("nr_pal.in");
- ofstream fout("nr_pal.out");
- fin >> n;
- for (int i = 0; i < n; i++) {
- fin >> a >> b;
- int contor = 0;
- for (int j=a; j <=b; j++) {
- if (estePalindrom(j)) {
- contor++;
- }
- }
- fout << contor << endl;
- }
- fin.close();
- fout.close();
- return 0;
- }
- int estePalindrom(int x) {
- if (oglindit(x) == x) {
- return 1;
- } else {
- return 0;
- }
- }
- int oglindit(int n) {
- int rezultat = 0;
- while(n > 0) {
- int ultimaCifra = n % 10;
- rezultat = rezultat * 10 + ultimaCifra;
- n = n/10;
- }
- return rezultat;
- }
Advertisement
Add Comment
Please, Sign In to add comment