Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- int main()
- {
- int n;
- cout << "Введите n: ";
- cin >> n;
- int a[100], b[100], c[100];
- int d, e = 0, g = 0, h = 0, l = 0;
- cout << "Массив А: ";
- for (int i = 0; i < n; i++) {
- a[i] = rand() % 3 + 1;
- cout << a[i] << ' ';
- }
- for (int i = 0; i < n; i++) {
- d = 1;
- if (a[i] == a[i + 1]) {
- d++;
- c[e] = a[i];
- e++;
- i++;
- c[e] = a[i];
- while (a[i] == a[i + 1]) {
- e++;
- i++;
- c[e] = a[i];
- d++;
- }
- }
- b[l] = d;
- l++;
- }
- e = 0;
- cout << "\nДлины всех серий и значения элементов, образующие эти серии массива A:\n";
- for (int i = 0; i < l; i++, e++) {
- cout << b[i] << " - ";
- for (int j = 0; j < b[i]; j++) {
- cout << c[e] << ' ';
- }
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement