Advertisement
Eddie_1337

10 atestat

Dec 6th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. bool palindrom(int x) {
  8.     int y = x, z = 0;
  9.     while (y) {
  10.         z = z * 10 + y % 10;
  11.         y /= 10;
  12.     }
  13.     return x == z;
  14. }
  15.  
  16. int cif(int x) {
  17.     int c = 0;
  18.     while (x) {
  19.         c++;
  20.         x /= 10;
  21.     }
  22.     return c;
  23. }
  24.  
  25. int main() {
  26.     ifstream f("numere.in");
  27.     ofstream g("numere.out");
  28.     int n, x, v[1000], c = -1;
  29.     f >> n;
  30.     for (int i = 1; i <= n; i++) {
  31.         f >> x;
  32.         if (palindrom(x)) {
  33.             g << x << ' ';
  34.             if (cif(x) % 2) {
  35.                 c++;
  36.                 v[c] = x;
  37.             }
  38.         }
  39.     }
  40.     g << endl;
  41.     n = 1;
  42.     while (n) {
  43.         n = 0;
  44.         for (int i = 0; i <= c - 1; i++) {
  45.             if (v[i] > v[i + 1]) {
  46.                 n = 1;
  47.                 v[i] = v[i] + v[i + 1];
  48.                 v[i + 1] = v[i] - v[i + 1];
  49.                 v[i] = v[i] - v[i + 1];
  50.             }
  51.         }
  52.     }
  53.     for (int i = 0; i <= c; i++)
  54.         g << v[i] << ' ';
  55.     system("pause");
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement