bogdanNiculeasa

Pbinfo 2415 tema

Nov 25th, 2023
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream> // file stream
  3. using namespace std;
  4.  
  5. int oglindit(int z);
  6. int estePalindrom(int n);
  7. int main()
  8. {
  9.     int n, a,b;
  10.     ifstream fin("nr_pal.in");
  11.     ofstream fout("nr_pal.out");
  12.     fin >> n;
  13.     for (int i = 0; i < n; i++) {
  14.         fin >> a >> b;
  15.         int contor = 0;
  16.         for (int j=a; j <=b; j++) {
  17.             if (estePalindrom(j)) {
  18.                 contor++;
  19.             }
  20.         }
  21.         fout << contor << endl;
  22.     }
  23.  
  24.     fin.close();
  25.     fout.close();
  26.  
  27.     return 0;
  28. }
  29.  
  30.  
  31. int estePalindrom(int x) {
  32.     if (oglindit(x) == x) {
  33.         return 1;
  34.     } else {
  35.         return 0;
  36.     }
  37. }
  38.  
  39. int oglindit(int n) {
  40.     int rezultat = 0;
  41.     while(n > 0) {
  42.         int ultimaCifra = n % 10;
  43.         rezultat = rezultat * 10 + ultimaCifra;
  44.         n = n/10;
  45.     }
  46.  
  47.     return rezultat;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment