Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. #include <iostream>
  2. #include<time.h>
  3. using namespace std;
  4.  
  5. void main()
  6. {
  7. setlocale(LC_ALL, "ukr");
  8. srand(time(NULL));
  9. const int n = 15;
  10. bool change = true;
  11. int arr[n], m = 0;
  12.  
  13. for (int i = 0; i < n; i++)
  14. {
  15. arr[i] = rand() % 10 - 5;
  16. cout << arr[i] << " ";
  17. }
  18. cout << endl;
  19. int maxcount = 0;
  20. for (int i = 0; i < n; i++)
  21. {
  22. int count = 0;
  23. if (arr[i] < 0) {
  24. for (int j = i; j < n; j++)
  25. {
  26. if (arr[j] < 0) {
  27. count++;
  28. if (count > maxcount) { maxcount = count; }
  29. cout << count << " ";
  30. }
  31. }
  32. }
  33. }
  34. cout << endl << maxcount << endl;
  35. }
  36.  
  37. for (int j = i; j < n; j++)
  38. {
  39. if (arr[j] < 0) {
  40. count++;
  41. if (count > maxcount) { maxcount = count; }
  42.  
  43. }else{
  44. count = 0; //cбрасывать значение count кто будет?
  45. }
  46. }
  47.  
  48. -3 -5 -4 3 4 -5 1 0 -3 -1 -1 -2 -5 -5 0
  49.  
  50. 6
  51.  
  52. #include <range/v3/all.hpp>
  53.  
  54. int main()
  55. {
  56. int v[] { -2, 0, 2, -1, -2, -11, -2, 3, 5, 1, -1, -1, 1, -2, -1, 2 };
  57.  
  58. int m = ranges::max(v
  59. | ranges::view::group_by([](int a, int b){return (a < 0) && (b < 0);})
  60. | ranges::view::transform(ranges::distance)
  61. );
  62.  
  63. assert(m == 4);
  64. }
  65.  
  66. int main()
  67. {
  68. int a[12] {-1, -2, -11, -2, 3, 5, 1, -1, -1, 1, -2, -1};
  69.  
  70. unsigned current = 0, maxnegative = 0;
  71.  
  72. for (int i = 0; i < 12; ++i) {
  73. if (a[i] < 0) {
  74. ++current;
  75. if (current > maxnegative) maxnegative = current;
  76. } else {
  77. current = 0;
  78. }
  79. }
  80.  
  81. cout << maxnegative << endl;
  82. return 0;
  83. }
  84.  
  85. #include <vector>
  86. #include <rxcpp/rx.hpp>
  87.  
  88. int main()
  89. {
  90. std::vector<int> v{ -1, -2, -11, -2, 3, 5, 1, -1, -1, 1, -2, -1, 1, 2, 1, 0 };
  91.  
  92. auto m = rxcpp::observable<>::iterate(v)
  93. .scan(0, [](int a, int i) { return (i < 0) ? a + 1 : 0; })
  94. .scan(0, [](int a, int i) { return std::max<int>(a, i); })
  95. .distinct_until_changed();
  96.  
  97. m | rxcpp::operators::subscribe<int>(rxcpp::util::println(std::cout));
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement