Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n;
  8. cout << "Введите n: ";
  9. cin >> n;
  10.  
  11. int a[100], b[100], c[100];
  12. int d, e = 0, g = 0, h = 0, l = 0;
  13.  
  14. cout << "Массив А: ";
  15. for (int i = 0; i < n; i++) {
  16. a[i] = rand() % 3 + 1;
  17. cout << a[i] << ' ';
  18. }
  19.  
  20. for (int i = 0; i < n; i++) {
  21. d = 1;
  22. if (a[i] == a[i + 1]) {
  23. d++;
  24. c[e] = a[i];
  25. e++;
  26. i++;
  27. c[e] = a[i];
  28. while (a[i] == a[i + 1]) {
  29. e++;
  30. i++;
  31. c[e] = a[i];
  32. d++;
  33. }
  34. }
  35. b[l] = d;
  36. l++;
  37. }
  38.  
  39. e = 0;
  40. cout << "\nДлины всех серий и значения элементов, образующие эти серии массива A:\n";
  41. for (int i = 0; i < l; i++, e++) {
  42. cout << b[i] << " - ";
  43. for (int j = 0; j < b[i]; j++) {
  44. cout << c[e] << ' ';
  45. }
  46. cout << '\n';
  47. }
  48.  
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement