Guest User

Untitled

a guest
Jul 28th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 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; //сбрасывать значение 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. int main()
  53. {
  54. int a[12] {-1, -2, -11, -2, 3, 5, 1, -1, -1, 1, -2, -1};
  55.  
  56. unsigned current = 0, maxnegative = 0;
  57.  
  58. for (int i = 0; i < 12; ++i) {
  59. if (a[i] < 0) {
  60. ++current;
  61. if (current > maxnegative) maxnegative = current;
  62. } else {
  63. current = 0;
  64. }
  65. }
  66.  
  67. cout << maxnegative << endl;
  68. return 0;
  69. }
Add Comment
Please, Sign In to add comment