You are viewing a single comment's thread. Return to all comments →
it's working fine. Awesome man! Thanks!
vector<int> reverse_sum(vector<int> stack) { reverse(stack.begin(),stack.end()); for(int i=1; i<stack.size(); i++) stack[i]=stack[i]+stack[i-1]; reverse(stack.begin(),stack.end()); return stack; } int max_height ( vector <int> s1, vector <int> s2, vector <int> s3) { int h=0; for(int i=0; i<s1.size(); i++) if(find(s2.begin(),s2.end(),s1[i]) != s2.end()) if(find(s3.begin(),s3.end(),s1[i]) != s3.end()) { h=s1[i]; break; } return h; } int main() { ifstream infile("i.txt"); int n1,n2,n3; cin>>n1>>n2>>n3; vector<int> stack1(n1),stack2(n2),stack3(n3); for(int i=0; i<n1; i++) cin>>stack1[i]; for(int i=0; i<n2; i++) cin>>stack2[i]; for(int i=0; i<n3; i++) cin>>stack3[i]; stack1=reverse_sum(stack1); stack2=reverse_sum(stack2); stack3=reverse_sum(stack3); if(stack1.size()<=stack2.size() && stack1.size()<=stack3.size()) cout<<max_height(stack1,stack2,stack3); else if(stack2.size()<=stack1.size() && stack2.size()<=stack3.size()) cout<<max_height(stack2,stack1,stack3); else cout<<max_height(stack3,stack1,stack2); 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 →
it's working fine. Awesome man! Thanks!