SHARE
TWEET

Tpb5 22/1/2020

STANAANDREY Jan 22nd, 2020 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. #define OUTFILE "Nr.txt"
  6. #define NMAX 100
  7. int n, v[NMAX];
  8.  
  9. void Citeste(int& n, int a[])
  10. {
  11.     cin >> n;
  12.     for (int i = 0; i < n; i++)
  13.         cin >> a[i];
  14. }
  15.  
  16. int Cif(int x)
  17. {
  18.     while (x > 9)
  19.         x /= 10;
  20.  
  21.     return x;
  22. }
  23.  
  24. void Sortare(int n, int a[])
  25. {
  26.     int sortat = 0;
  27.     while (!sortat)
  28.     {
  29.         sortat = 1;
  30.         for (int i = 0; i < n - 1; i++)
  31.             if (Cif(a[i]) > Cif(a[i + 1]))
  32.             {
  33.                 swap(a[i], a[i + 1]);
  34.                 sortat = 0;
  35.             }
  36.     }
  37. }
  38.  
  39. void Scrie(int n, int a[])
  40. {
  41.     int ante = a[0];
  42.     ofstream fout(OUTFILE);
  43.     fout << a[0] << ' ';
  44.     for (int i = 1; i < n; i++)
  45.     {
  46.         if (Cif(ante) != Cif(a[i]))
  47.             fout << '\n';
  48.         fout << a[i] << ' ';
  49.         ante = a[i];
  50.     }
  51.  
  52.     fout.close();
  53. }
  54.  
  55. int main()
  56. {
  57.     Citeste(n, v);
  58.     Sortare(n, v);
  59.     Scrie(n, v);
  60.     return 0;
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top