You are viewing a single comment's thread. Return to all comments →
bool isnumber(int num , vector<int> arr , int sizeofvec){ for(int i = sizeofvec ; i > 0 ; i-- ){ if(arr[i] == num ){ return true; } } return false; } int main(){ int n1; int n2; int n3; int temp; cin >> n1 >> n2 >> n3; vector<int> h1(n1+1); for(int h1_i = 0;h1_i < n1;h1_i++){ cin >> h1[h1_i]; } vector<int> h2(n2+1); for(int h2_i = 0;h2_i < n2;h2_i++){ cin >> h2[h2_i]; } vector<int> h3(n3+1); for(int h3_i = 0;h3_i < n3;h3_i++){ cin >> h3[h3_i]; } h1[n1+1] = 0 ; h2[n2+1] = 0 ; h3[n3+1] = 0 ; //Step - 2 = For revering and adding .. Reverse side adding is performed for(int h1_i = (n1 - 1) ; h1_i >=0; h1_i--){ h1[h1_i] = h1[h1_i] + h1[h1_i + 1]; } for(int h2_i = (n2 - 1) ;h2_i >=0;h2_i--){ h2[h2_i] = h2[h2_i] + h2[h2_i + 1]; } for(int h3_i = (n3 - 1) ;h3_i >=0;h3_i--){ h3[h3_i] = h3[h3_i] + h3[h3_i + 1]; } //step - 3 = Checking from last if the same number exists in other two arrays for(int h1_i = (n1 - 1) ; h1_i >=0; h1_i--){ if(isnumber(h1[h1_i] , h2, n2) && isnumber(h1[h1_i] , h3 ,n3) ){ temp = h1[h1_i] ; break; }else{ temp = 0; } } cout<<temp; return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Equal Stacks
You are viewing a single comment's thread. Return to all comments →