Advertisement
Eddie_1337

6 atestat

Nov 3rd, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. bool palindrom(int x) {
  7.     short y = x, z = 0;
  8.     while (y != 0) {
  9.         z = z * 10 + y % 10;
  10.         y /= 10;
  11.     }
  12.     return x == z;
  13. }
  14.  
  15. int main() {
  16.     bool a = 0;
  17.     int x, p, u, max;
  18.     ifstream f("numere.in");
  19.     ofstream g("numere.out");
  20.     while (f >> x)
  21.         if (palindrom(x)) {
  22.             u = x;
  23.             if (!a) {
  24.                 p = x;
  25.                 max = x;
  26.                 a = 1;
  27.             }
  28.             if (x > max)
  29.                 max = x;
  30.         }
  31.     g << max << endl << p << ' ' << u;
  32.     f.close();
  33.     g.close();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement