Advertisement
J00ker

(10-13)T

Oct 13th, 2014
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int a[9] = {2, 2, 3, 4, 3, 7, 10, 9, 1};
  6. int b[10] = {1, 0, 0, 0, 1, 1, 0, 0, 0, 0};
  7. int s = 10, n_a = 9, n_b = 10;
  8.  
  9. int NrSecv(int a[], int n, int s)
  10. {
  11. int nr_s = 0;
  12. for(int i = 0; i < n; i++)
  13. {
  14. int nr = a[i];
  15. for(int j = i+1; nr < s; j++)
  16. nr += a[j];
  17. if(nr == s) nr_s++;
  18. }
  19. return nr_s;
  20. }
  21.  
  22. int Secv0(int a[], int n)
  23. {
  24. int nr0 = 0, nr0max = 0;
  25. for(int i = 0; i < n; i++)
  26. {
  27. if(a[i] == 1) nr0 = 0;
  28. else nr0++;
  29.  
  30. if(nr0 > nr0max) nr0max = nr0;
  31. }
  32. return nr0max;
  33. }
  34.  
  35. void SecvDiv(int a[], int n, int &s, int &d)
  36. {
  37. int sum;
  38. for(s = 0; s < n; s++)
  39. {
  40. sum = 0;
  41. for(d = s; d < n; d++)
  42. {
  43. sum += a[d];
  44. if(sum % n == 0) return;
  45. }
  46. }
  47. }
  48.  
  49. int main()
  50. {
  51. cout << NrSecv(a, n_a, s) << "\n";
  52. cout << Secv0(b, n_b) << "\n";
  53.  
  54. int s = 0, d = 0;
  55. SecvDiv(a, n_a, s, d);
  56. cout << s << " " << d;
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement