atleat we tried (hackerrank)

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include<stack> using namespace std; int height(stack<int>s) { int sum=0; stack<int>d=s; while(!d.empty()) { sum=sum+d.top(); d.pop(); } return sum; } stack<int> s1,s2,s3; int main() { int n1,n2,n3,h1,h2,h3; cin>>n1>>n2>>n3; int i,x; int a1[1000],a2[1000],a3[1000]; for(i=0;i<n1;i++) { cin>>a1[i]; } for(i=0;i<n2;i++) { cin>>a2[i]; } for(i=0;i<n3;i++) { cin>>a3[i]; } for(i=n1-1;i>=0;i--) { s1.push(a1[i]); } cout<<endl; for(i=n2-1;i>=0;i--) {s2.push(a2[i]); } cout<<endl; for(i=n3-1;i>=0;i--) {s3.push(a3[i]); } h1=height(s1); h2=height(s2); h3=height(s3); if(h1==h2&&h2==h3) cout<<h1; else{ while(1) { if(h3<h1&&h3<h2) { s1.pop(); s2.pop(); } else if(h2<h1&&h2<h3) { s1.pop(); s3.pop(); } else if(h3>h1&&h3>h2) s3.pop(); else if(h1<h2&&h1<h3){ s2.pop(); s3.pop(); } else if(h1>h2&&h1>h3) s1.pop(); else s2.pop(); h1=height(s1); h2=height(s2); h3=height(s3); cout<<h1<<' '<<h2<<' '<<h3<<endl; if (h1==h2&&h2==h3) break; } cout<<h1; } */ return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines