Advertisement
Guest User

Untitled

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