Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- #define OUTFILE "Nr.txt"
- #define NMAX 100
- int n, v[NMAX];
- void Citeste(int& n, int a[])
- {
- cin >> n;
- for (int i = 0; i < n; i++)
- cin >> a[i];
- }
- int Cif(int x)
- {
- while (x > 9)
- x /= 10;
- return x;
- }
- void Sortare(int n, int a[])
- {
- int sortat = 0;
- while (!sortat)
- {
- sortat = 1;
- for (int i = 0; i < n - 1; i++)
- if (Cif(a[i]) > Cif(a[i + 1]))
- {
- swap(a[i], a[i + 1]);
- sortat = 0;
- }
- }
- }
- void Scrie(int n, int a[])
- {
- int ante = a[0];
- ofstream fout(OUTFILE);
- fout << a[0] << ' ';
- for (int i = 1; i < n; i++)
- {
- if (Cif(ante) != Cif(a[i]))
- fout << '\n';
- fout << a[i] << ' ';
- ante = a[i];
- }
- fout.close();
- }
- int main()
- {
- Citeste(n, v);
- Sortare(n, v);
- Scrie(n, v);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement