Advertisement
Eddie_1337

7 atestat

Nov 9th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int ncif(int x) {
  7.     int c = 0;
  8.     while (x) {
  9.         c++;
  10.         x /= 10;
  11.     }
  12.     return c;
  13. }
  14.  
  15. int main() {
  16.     ifstream f("atestat.in");
  17.     ofstream g("atestat.out");
  18.     int x, max = -1, min = 9999, n;
  19.     f >> n;
  20.     for (int i = 1; i <= n; i++) {
  21.         f >> x;
  22.         if (x % 2)
  23.             g << ncif(x) << ' ';
  24.         if (x < min)
  25.             min = x;
  26.         if (x > max)
  27.             max = x;
  28.     }
  29.     g << endl;
  30.     if (!min && max)
  31.         g << max;
  32.     else
  33.         if (min && !max)
  34.             g << min;
  35.         else {
  36.             while (min != max) {
  37.                 if (max > min)
  38.                     max -= min;
  39.                 else
  40.                     min -= max;
  41.             }
  42.             g << max;
  43.         }
  44.     f.close();
  45.     g.close();
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement