Advertisement
Guest User

Untitled

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