Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3.  
  4. using namespace std;
  5.  
  6. bool splitArray(int vec[], int size){
  7.    int s=0;
  8.    for (int i = 0; i<=size; i++)
  9.    {
  10.        int k=0, l=0;
  11.        for (int j=0;j<=i;j++)
  12.        {
  13.             k=k+vec[j];
  14.             l=l+vec(size-j+1)
  15.        }
  16.        if (k==l) return true
  17.    }
  18.  
  19. }
  20.  
  21.  
  22. int main(){
  23.     int p;
  24.     int test1[1] = {1};
  25.     cout << splitArray(test1,1) << endl; // FALSE
  26.  
  27.     int test2[5] = {1, 1, 1, 2, 1};
  28.     cout << splitArray(test2,5)  << endl; // TRUE
  29.  
  30.     int test3[5] = {2, 1, 1, 2, 1};
  31.     cout << splitArray(test3,5)  << endl; // FALSE
  32.  
  33.     int test4[5] = {10, 0, 1, -1, 10};
  34.     cout << splitArray(test4,5)  << endl; // TRUE
  35.  
  36.     int test5[2] = {10, 10};
  37.     cout << splitArray(test5,2)  << endl; // TRUE
  38.  
  39.     int test6[7] = {1, 2, 3, 1, 0, 2, 3};
  40.     cout << splitArray(test6,7) << endl; // TRUE
  41.  
  42.     cout<<"pauza";
  43.      cin>>p;
  44.      //getchar();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement